Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust specs for OH4.1 QuantityType changes #145

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions spec/openhab/core/types/quantity_type_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@
# quantity type operand
expect(QuantityType.new("50 °F") + QuantityType.new("50 °F")).to eql QuantityType.new("100.0 °F")
expect(QuantityType.new("50 °F") - QuantityType.new("25 °F")).to eql QuantityType.new("25.0 °F")
expect((QuantityType.new("100 °F") / QuantityType.new("2 °F")).to_i).to be 50
expect((QuantityType.new("100 W") / QuantityType.new("2 W")).to_i).to be 50
expect(QuantityType.new("50 °F") + -QuantityType.new("25 °F")).to eql QuantityType.new("25.0 °F")

# numeric operand
expect(QuantityType.new("50 °F") * 2).to eql QuantityType.new("100.0 °F")
expect(QuantityType.new("100 °F") / 2).to eql QuantityType.new("50.0 °F")
expect(QuantityType.new("50 °F") * 2.0).to eql QuantityType.new("100.0 °F")
expect(QuantityType.new("100 °F") / 2.0).to eql QuantityType.new("50.0 °F")
expect(QuantityType.new("50 W") * 2).to eql QuantityType.new("100.0 W")
expect(QuantityType.new("100 W") / 2).to eql QuantityType.new("50.0 W")
expect(QuantityType.new("50 W") * 2.0).to eql QuantityType.new("100.0 W")
expect(QuantityType.new("100 W") / 2.0).to eql QuantityType.new("50.0 W")

# DecimalType operand
expect(QuantityType.new("50 °F") * DecimalType.new(2)).to eql QuantityType.new("100.0 °F")
expect(QuantityType.new("100 °F") / DecimalType.new(2)).to eql QuantityType.new("50.0 °F")
expect(QuantityType.new("50 °F") * DecimalType.new(2.0)).to eql QuantityType.new("100.0 °F")
expect(QuantityType.new("100 °F") / DecimalType.new(2.0)).to eql QuantityType.new("50.0 °F")
expect(QuantityType.new("50 W") * DecimalType.new(2)).to eql QuantityType.new("100.0 W")
expect(QuantityType.new("100 W") / DecimalType.new(2)).to eql QuantityType.new("50.0 W")
expect(QuantityType.new("50 W") * DecimalType.new(2.0)).to eql QuantityType.new("100.0 W")
expect(QuantityType.new("100 W") / DecimalType.new(2.0)).to eql QuantityType.new("50.0 W")
end

it "can be compared" do
Expand Down
10 changes: 9 additions & 1 deletion spec/openhab/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,18 @@
expect((c + f).format("%.1f %unit%")).to eq "44.1 °C"
expect(f - 2 < 20).to be true
expect(2 + c == 25).to be true
expect(2 * c == 46).to be true
expect((2 * (f + c) / 2) < 45).to be true
expect([c, f, 2].min).to be 2
end

# The behavior of Multiplications and Divisions with non zero-based units such as °C and °F
# (as opposed to Kelvin) is different between OH 4.1 and previous versions.
# See https://github.com/openhab/openhab-core/pull/3792
# Use a zero-based unit to have a consistent result across OH versions.
w = 5 | "W"
unit("W") do
expect(2 * w == 10).to be true
end
end

it "supports setting multiple dimensions at once" do
Expand Down