From 501445e6c4a9d71c874486ce5fcca635357f3fc0 Mon Sep 17 00:00:00 2001 From: Jimmy Tanagra Date: Wed, 13 Sep 2023 10:48:26 +1000 Subject: [PATCH] Adjust specs for OH4.1 QuantityType changes Signed-off-by: Jimmy Tanagra --- spec/openhab/core/types/quantity_type_spec.rb | 18 +++++++++--------- spec/openhab/dsl_spec.rb | 10 +++++++++- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/spec/openhab/core/types/quantity_type_spec.rb b/spec/openhab/core/types/quantity_type_spec.rb index e1bfa993fd..5c5812991e 100644 --- a/spec/openhab/core/types/quantity_type_spec.rb +++ b/spec/openhab/core/types/quantity_type_spec.rb @@ -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 diff --git a/spec/openhab/dsl_spec.rb b/spec/openhab/dsl_spec.rb index 2b4c92432a..642de60c3b 100644 --- a/spec/openhab/dsl_spec.rb +++ b/spec/openhab/dsl_spec.rb @@ -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