Skip to content

Commit

Permalink
Adjust specs for OH4.1 QuantityType changes
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmy Tanagra <[email protected]>
  • Loading branch information
jimtng committed Sep 13, 2023
1 parent 3d83170 commit 501445e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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

0 comments on commit 501445e

Please sign in to comment.