From ee7fbcccaa565087bdc5a2486d20eed6d548ae02 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Fri, 15 Nov 2024 12:54:42 +0100 Subject: [PATCH 1/3] use zeroKW and zeroKWH within thermal unit tests --- .../ThermalGridWithHouseAndStorageSpec.scala | 23 +++++++------- .../ThermalGridWithHouseOnlySpec.scala | 17 +++++----- .../ThermalGridWithStorageOnlySpec.scala | 31 ++++++++++--------- 3 files changed, 37 insertions(+), 34 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala index 1ea45a656d..f2829532cd 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseAndStorageSpec.scala @@ -13,6 +13,7 @@ import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{ HouseTemperatureLowerBoundaryReached, HouseTemperatureUpperBoundaryReached, } +import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWH} import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageState import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageThreshold.{ StorageEmpty, @@ -103,15 +104,15 @@ class ThermalGridWithHouseAndStorageSpec testGridAmbientTemperature, ThermalGrid.startingState(thermalGrid), ) - houseDemand.required should approximate(KilowattHours(0d)) + houseDemand.required should approximate(zeroKWH) houseDemand.possible should approximate(KilowattHours(31.05009722d)) storageDemand.required should approximate(KilowattHours(1150d)) storageDemand.possible should approximate(KilowattHours(1150d)) updatedThermalGridState.houseState shouldBe Some( - ThermalHouseState(10800, Kelvin(292.0799935185185), Kilowatts(0d)) + ThermalHouseState(10800, Kelvin(292.0799935185185), zeroKW) ) updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d)) + ThermalStorageState(10800, zeroKWH, zeroKW) ) } @@ -136,10 +137,10 @@ class ThermalGridWithHouseAndStorageSpec storageDemand.required should approximate(KilowattHours(1150d)) storageDemand.possible should approximate(KilowattHours(1150d)) updatedThermalGridState.houseState shouldBe Some( - ThermalHouseState(10800, Celsius(15.959996296296296), Kilowatts(0d)) + ThermalHouseState(10800, Celsius(15.959996296296296), zeroKW) ) updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d)) + ThermalStorageState(10800, zeroKWH, zeroKW) ) } } @@ -159,7 +160,7 @@ class ThermalGridWithHouseAndStorageSpec storageState.copy(storedEnergy = initialLoading) ) ) - val externalQDot = Kilowatts(0d) + val externalQDot = zeroKW val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( @@ -216,7 +217,7 @@ class ThermalGridWithHouseAndStorageSpec ) => houseTick shouldBe 0L innerTemperature should approximate(Celsius(18.9999d)) - qDotHouse should approximate(Kilowatts(0d)) + qDotHouse should approximate(zeroKW) storageTick shouldBe 0L storedEnergy should approximate(initialLoading) @@ -228,7 +229,7 @@ class ThermalGridWithHouseAndStorageSpec } "revising infeed from storage to house" should { - val zeroInflux = Kilowatts(0d) + val zeroInflux = zeroKW val tick = 3600L val ambientTemperature = Celsius(14d) "hand back unaltered information if needed information is missing" in { @@ -371,7 +372,7 @@ class ThermalGridWithHouseAndStorageSpec ( ThermalStorageState( tick, - KilowattHours(0d), + zeroKWH, testGridQDotInfeed, ), Some(StorageEmpty(tick)), @@ -517,7 +518,7 @@ class ThermalGridWithHouseAndStorageSpec .getOrElse(fail("No initial storage state found")) ) - qDotStorage should approximate(Kilowatts(0d)) + qDotStorage should approximate(zeroKW) case _ => fail("Thermal grid state has been calculated wrong.") } @@ -554,7 +555,7 @@ class ThermalGridWithHouseAndStorageSpec ) => houseTick shouldBe 0L innerTemperature should approximate(Celsius(20.99999167d)) - qDotHouse should approximate(Kilowatts(0d)) + qDotHouse should approximate(zeroKW) storageTick shouldBe 0L storedEnergy should approximate( diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala index eb447d0fc4..c0d6226694 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -13,6 +13,7 @@ import edu.ie3.simona.model.thermal.ThermalHouse.ThermalHouseThreshold.{ HouseTemperatureLowerBoundaryReached, HouseTemperatureUpperBoundaryReached, } +import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWH} import edu.ie3.simona.test.common.UnitSpec import squants.energy._ import squants.thermal.Celsius @@ -90,10 +91,10 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { houseDemand.required should approximate(expectedHouseDemand.required) houseDemand.possible should approximate(expectedHouseDemand.possible) - storageDemand.required should approximate(KilowattHours(0d)) - storageDemand.possible should approximate(KilowattHours(0d)) + storageDemand.required should approximate(zeroKWH) + storageDemand.possible should approximate(zeroKWH) updatedThermalGridState.houseState shouldBe Some( - ThermalHouseState(10800, Kelvin(292.0799935185185), Kilowatts(0d)) + ThermalHouseState(10800, Kelvin(292.0799935185185), zeroKW) ) updatedThermalGridState.storageState shouldBe None } @@ -108,7 +109,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { "deliver the house state by just letting it cool down, if just no infeed is given" in { val tick = 0L val gridState = ThermalGrid.startingState(thermalGrid) - val externalQDot = Megawatts(0d) + val externalQDot =zeroKW val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption( @@ -154,7 +155,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ) => tick shouldBe 0L innerTemperature should approximate(Celsius(18.9999d)) - qDot should approximate(Megawatts(0d)) + qDot should approximate(zeroKW) case _ => fail("Thermal grid state has been calculated wrong.") } reachedThreshold shouldBe Some( @@ -239,7 +240,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ) => tick shouldBe 0L innerTemperature should approximate(Celsius(18.9999d)) - qDot should approximate(Megawatts(0d)) + qDot should approximate(zeroKW) thresholdTick shouldBe 154285L case _ => fail("Thermal grid state updated failed") } @@ -251,7 +252,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, testGridAmbientTemperature, - Megawatts(0d), + zeroKW, ) match { case ( ThermalGridState( @@ -262,7 +263,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { ) => tick shouldBe 0L innerTemperature should approximate(Celsius(18.9999d)) - qDot should approximate(Kilowatts(0d)) + qDot should approximate(zeroKW) thresholdTick shouldBe 154285L case _ => fail("Thermal grid state updated failed") } diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala index 93a45e3180..9ef8dbb424 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithStorageOnlySpec.scala @@ -17,6 +17,7 @@ import edu.ie3.simona.model.thermal.ThermalStorage.ThermalStorageThreshold.{ StorageFull, } import edu.ie3.simona.test.common.UnitSpec +import edu.ie3.util.scala.quantities.DefaultQuantities.{zeroKW, zeroKWH} import squants.energy._ import squants.thermal.Celsius import squants.{Energy, Power, Temperature} @@ -88,13 +89,13 @@ class ThermalGridWithStorageOnlySpec ThermalGrid.startingState(thermalGrid), ) - houseDemand.required should approximate(KilowattHours(0d)) - houseDemand.possible should approximate(KilowattHours(0d)) + houseDemand.required should approximate(zeroKWH) + houseDemand.possible should approximate(zeroKWH) storageDemand.required should approximate(KilowattHours(1150d)) storageDemand.possible should approximate(KilowattHours(1150d)) updatedThermalGridState.houseState shouldBe None updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800, KilowattHours(0d), Kilowatts(0d)) + ThermalStorageState(10800, zeroKWH, zeroKW) ) } @@ -108,17 +109,17 @@ class ThermalGridWithStorageOnlySpec testGridAmbientTemperature, ThermalGridState( None, - Some(ThermalStorageState(0L, KilowattHours(575d), Kilowatts(0d))), + Some(ThermalStorageState(0L, KilowattHours(575d), zeroKW)), ), ) - houseDemand.required should approximate(KilowattHours(0d)) - houseDemand.possible should approximate(KilowattHours(0d)) - storageDemand.required should approximate(KilowattHours(0d)) + houseDemand.required should approximate(zeroKWH) + houseDemand.possible should approximate(zeroKWH) + storageDemand.required should approximate(zeroKWH) storageDemand.possible should approximate(KilowattHours(575d)) updatedThermalGridState.houseState shouldBe None updatedThermalGridState.storageState shouldBe Some( - ThermalStorageState(10800L, KilowattHours(575d), Kilowatts(0d)) + ThermalStorageState(10800L, KilowattHours(575d), zeroKW) ) } } @@ -138,7 +139,7 @@ class ThermalGridWithStorageOnlySpec ThermalStorageState( 0L, KilowattHours(200d), - Kilowatts(0d), + zeroKW, ) ) ) @@ -191,7 +192,7 @@ class ThermalGridWithStorageOnlySpec Some(ThermalStorageState(tick, storedEnergy, qDot)), ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) + storedEnergy should approximate(zeroKWH) qDot should approximate(testGridQDotInfeed) case _ => fail("Thermal grid state has been calculated wrong.") } @@ -217,7 +218,7 @@ class ThermalGridWithStorageOnlySpec Some(ThermalStorageState(tick, storedEnergy, qDot)), ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) + storedEnergy should approximate(zeroKWH) qDot should approximate(testGridQDotInfeed) case _ => fail("Thermal grid state updated failed") } @@ -233,7 +234,7 @@ class ThermalGridWithStorageOnlySpec ThermalStorageState( 0L, KilowattHours(200d), - Kilowatts(0d), + zeroKW, ) ) ), @@ -262,7 +263,7 @@ class ThermalGridWithStorageOnlySpec ThermalGrid.startingState(thermalGrid), testGridAmbientTemperature, testGridAmbientTemperature, - Kilowatts(0d), + zeroKW, ) updatedState match { case ( @@ -273,8 +274,8 @@ class ThermalGridWithStorageOnlySpec None, ) => tick shouldBe 0L - storedEnergy should approximate(KilowattHours(0d)) - qDot should approximate(Megawatts(0d)) + storedEnergy should approximate(zeroKWH) + qDot should approximate(zeroKW) case _ => fail("Thermal grid state updated failed") } From bb2f81027a092441a1e9d7a8ce2ea25e11bfeaad Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Fri, 15 Nov 2024 12:58:05 +0100 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b683cd1327..4a3acbb5d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -97,6 +97,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rewrote StorageModelTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Updated `ExtEvSimulationClasses` [#898](https://github.com/ie3-institute/simona/issues/898) - Refactoring of `ThermalGrid.energyGrid` to distinguish between demand of house and storage [#928](https://github.com/ie3-institute/simona/issues/928) +- Refactoring to use zeroKW and zeroKWH in thermal grid unit tests [#1023](https://github.com/ie3-institute/simona/issues/1023) ### Fixed - Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505) From 86fcf1ee5976ff984bb7c6b0929f2369ead3f88c Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Fri, 15 Nov 2024 12:58:16 +0100 Subject: [PATCH 3/3] fmt --- .../ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala index c0d6226694..d50b1e558a 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalGridWithHouseOnlySpec.scala @@ -109,7 +109,7 @@ class ThermalGridWithHouseOnlySpec extends UnitSpec with ThermalHouseTestData { "deliver the house state by just letting it cool down, if just no infeed is given" in { val tick = 0L val gridState = ThermalGrid.startingState(thermalGrid) - val externalQDot =zeroKW + val externalQDot = zeroKW val (updatedGridState, reachedThreshold) = thermalGrid invokePrivate handleConsumption(