From 5aa8ce767e113529ce93cc04a08a171c42db71ed Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Fri, 2 Aug 2024 00:17:03 +0200 Subject: [PATCH 1/6] Rewrote ThermalHouseTest from groovy to scala --- CHANGELOG.md | 1 + .../simona/model/thermal/ThermalHouse.scala | 12 +- .../model/thermal/ThermalHouseTest.groovy | 129 --------------- .../model/thermal/ThermalHouseSpec.scala | 149 ++++++++++++++++++ 4 files changed, 156 insertions(+), 135 deletions(-) delete mode 100644 src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy create mode 100644 src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala diff --git a/CHANGELOG.md b/CHANGELOG.md index 468de1d410..fa53cb67a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rewrote SystemComponentTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Converting remaining rst files to markdown [#838](https://github.com/ie3-institute/simona/issues/838) - Merging both `FixedFeedInModelSpec` tests [#870](https://github.com/ie3-institute/simona/issues/870) +- Rewrote ThermalHouseTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) ### Fixed - Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658) diff --git a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala index c08a6a3114..9e186f3614 100644 --- a/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala +++ b/src/main/scala/edu/ie3/simona/model/thermal/ThermalHouse.scala @@ -192,7 +192,7 @@ final case class ThermalHouse( * @return * new inner temperature */ - private def newInnerTemperature( + def newInnerTemperature( thermalPower: Power, duration: Time, currentInnerTemperature: Temperature, @@ -221,7 +221,7 @@ final case class ThermalHouse( * @return * new inner temperature */ - private def calcNewInnerTemperature( + def calcNewInnerTemperature( oldInnerTemperature: Temperature, temperatureChange: Temperature, ): Temperature = @@ -235,7 +235,7 @@ final case class ThermalHouse( * @return * temperature change */ - private def calcInnerTemperatureChange( + def calcInnerTemperatureChange( thermalEnergyChange: Energy ): Temperature = { thermalEnergyChange / ethCapa @@ -250,7 +250,7 @@ final case class ThermalHouse( * @return * thermal energy change */ - private def calcThermalEnergyChange( + def calcThermalEnergyChange( thermalEnergyGain: Energy, thermalEnergyLoss: Energy, ): Energy = @@ -265,7 +265,7 @@ final case class ThermalHouse( * @return * resulting thermal energy gain */ - private def calcThermalEnergyGain( + def calcThermalEnergyGain( pThermal: Power, time: Time, ): Energy = pThermal * time @@ -282,7 +282,7 @@ final case class ThermalHouse( * @return * resulting thermal energy loss */ - private def calcThermalEnergyLoss( + def calcThermalEnergyLoss( innerTemperature: Temperature, ambientTemperature: Temperature, time: Time, diff --git a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy b/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy deleted file mode 100644 index f23d532b03..0000000000 --- a/src/test/groovy/edu/ie3/simona/model/thermal/ThermalHouseTest.groovy +++ /dev/null @@ -1,129 +0,0 @@ -/* - * © 2021. TU Dortmund University, - * Institute of Energy Systems, Energy Efficiency and Energy Economics, - * Research group Distribution grid planning and operation - */ - -package edu.ie3.simona.model.thermal - -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATTHOUR_PER_KELVIN -import static edu.ie3.util.quantities.PowerSystemUnits.KILOWATT_PER_KELVIN -import static tech.units.indriya.quantity.Quantities.getQuantity -import static tech.units.indriya.unit.Units.CELSIUS - -import edu.ie3.datamodel.models.StandardUnits -import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput -import edu.ie3.util.scala.quantities.Sq -import spock.lang.Shared -import spock.lang.Specification -import squants.energy.* -import squants.thermal.* -import squants.time.* - - -class ThermalHouseTest extends Specification { - - @Shared - static final Double TOLERANCE = 0.0001 - - static def buildThermalHouse(Double lowerBoundaryTemperature, Double upperBoundaryTemperature) { - def thermalHouseInput = new ThermalHouseInput( - UUID.randomUUID(), - "Thermal House", - null, - getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), - getQuantity(10.0, StandardUnits.HEAT_CAPACITY), - getQuantity(0, CELSIUS), // stub - getQuantity(upperBoundaryTemperature, CELSIUS), - getQuantity(lowerBoundaryTemperature, CELSIUS) - ) - return ThermalHouse.apply(thermalHouseInput) - } - - - def "Functions testing inner temperature work as expected"() { - given: - def thermalHouse = buildThermalHouse(18, 22) - - when: - Temperature innerTemp = Sq.create(innerTemperature, Celsius$.MODULE$) - def isHigher = thermalHouse.isInnerTemperatureTooHigh(innerTemp) - def isLower = thermalHouse.isInnerTemperatureTooLow(innerTemp, thermalHouse.lowerBoundaryTemperature()) - - then: - isHigher == isTooHigh - isLower == isTooLow - - where: - innerTemperature || isTooHigh | isTooLow - 17d || false | true - 17.98d || false | true - 18d || false | true - 20d || false | false - 22d || true | false - 22.02d || true | false - 23d || true | false - } - - def "Calculation of thermal energy change and new inner temperature is performed correctly"() { - given: - def thermalHouse = buildThermalHouse(18d, 22d) - def innerTemperature = Sq.create(20d, Celsius$.MODULE$) - - when: - def thermalEnergyGain = thermalHouse.calcThermalEnergyGain(Sq.create(100, Kilowatts$.MODULE$), Sq.create(3600, Seconds$.MODULE$)) - def thermalEnergyLoss = thermalHouse.calcThermalEnergyLoss(innerTemperature, Sq.create(10, Celsius$.MODULE$), Sq.create(3600, Seconds$.MODULE$)) - def thermalEnergyChange = thermalHouse.calcThermalEnergyChange(thermalEnergyGain, thermalEnergyLoss) - def innerTemperatureChange = thermalHouse.calcInnerTemperatureChange(thermalEnergyChange) - def newInnerTemperature = thermalHouse.calcNewInnerTemperature(innerTemperature, innerTemperatureChange) - - then: - Math.abs(100d - thermalEnergyGain.toKilowattHours()) < TOLERANCE - Math.abs(10d - thermalEnergyLoss.toKilowattHours()) < TOLERANCE - Math.abs(90d - thermalEnergyChange.toKilowattHours()) < TOLERANCE - Math.abs(9d - innerTemperatureChange.toKelvinScale()) < TOLERANCE - Math.abs(29d - newInnerTemperature.toCelsiusScale()) < TOLERANCE - } - - def "Comprising function to calculate new inner temperature works as expected"() { - given: - def thermalHouse = buildThermalHouse(18d, 22d) - def thermalPower = Sq.create(100d, Kilowatts$.MODULE$) - def duration = Sq.create(3600d, Seconds$.MODULE$) - def currentInnerTemperature = Sq.create(20d, Celsius$.MODULE$) - def ambientTemperature = Sq.create(10d, Celsius$.MODULE$) - - when: - def newInnerTemperature = thermalHouse.newInnerTemperature(thermalPower, duration, currentInnerTemperature, ambientTemperature) - - then: - Math.abs(newInnerTemperature.toCelsiusScale() - 29d) < TOLERANCE - } - - def "Check build method:"() { - given: - def thermalHouseInput = new ThermalHouseInput( - UUID.randomUUID(), - "Thermal House", - null, - getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), - getQuantity(10.0, StandardUnits.HEAT_CAPACITY), - getQuantity(0, CELSIUS), // stub - getQuantity(18, CELSIUS), - getQuantity(22, CELSIUS) - ) - - when: - def thermalHouse = buildThermalHouse(18, 22) - - then: - thermalHouse.id() == thermalHouseInput.id - thermalHouse.operatorInput() == thermalHouseInput.operator - thermalHouse.operationTime() == thermalHouseInput.operationTime - thermalHouse.bus() == thermalHouseInput.thermalBus - thermalHouse.ethLosses().toWattsPerKelvin() == thermalHouseInput.ethLosses.to(KILOWATT_PER_KELVIN).value.doubleValue() * 1000 - (thermalHouse.ethCapa().$times(Sq.create(1d, Kelvin$.MODULE$))).toKilowattHours() == thermalHouseInput.ethCapa.to(KILOWATTHOUR_PER_KELVIN).value.doubleValue() - thermalHouse.lowerBoundaryTemperature() == Sq.create(18, Celsius$.MODULE$) - thermalHouse.upperBoundaryTemperature() == Sq.create(22, Celsius$.MODULE$) - } -} diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala new file mode 100644 index 0000000000..85659fc7f4 --- /dev/null +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -0,0 +1,149 @@ +/* + * © 2021. TU Dortmund University, + * Institute of Energy Systems, Energy Efficiency and Energy Economics, + * Research group Distribution grid planning and operation + */ + +package edu.ie3.simona.model.thermal + +import edu.ie3.datamodel.models.StandardUnits +import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput +import edu.ie3.simona.test.common.UnitSpec +import squants.energy._ +import squants.thermal._ +import squants.time._ +import squants.{Energy, Temperature} +import tech.units.indriya.quantity.Quantities.getQuantity +import tech.units.indriya.unit.Units.CELSIUS + +import java.util.UUID + +class ThermalHouseSpec extends UnitSpec { + + implicit val tolerance: Temperature = Celsius(0.0001) + implicit val energyTolerance: Energy = KilowattHours(0.0001) + + def buildThermalHouse( + lowerBoundaryTemperature: Double, + upperBoundaryTemperature: Double, + ): ThermalHouse = { + val thermalHouseInput = new ThermalHouseInput( + UUID.randomUUID(), + "Thermal House", + null, + getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), + getQuantity(10.0, StandardUnits.HEAT_CAPACITY), + getQuantity(0, CELSIUS), // stub + getQuantity(upperBoundaryTemperature, CELSIUS), + getQuantity(lowerBoundaryTemperature, CELSIUS), + ) + ThermalHouse(thermalHouseInput) + } + + "ThermalHouse" should { + "Functions testing inner temperature work as expected" in { + val thermalHouse = buildThermalHouse(18, 22) + + val testCases = Seq( + (17d, false, true), + (17.98d, false, true), + (18d, false, true), + (20d, false, false), + (22d, true, false), + (22.02d, true, false), + (23d, true, false), + ) + + testCases.foreach { case (innerTemperature, isTooHigh, isTooLow) => + val innerTemp = Temperature(innerTemperature, Celsius) + val isHigher = thermalHouse.isInnerTemperatureTooHigh(innerTemp) + val isLower = thermalHouse.isInnerTemperatureTooLow( + innerTemp, + thermalHouse.lowerBoundaryTemperature, + ) + + isHigher shouldBe isTooHigh + isLower shouldBe isTooLow + } + } + + "Calculation of thermal energy change and new inner temperature is performed correctly" in { + val thermalHouse = buildThermalHouse(18, 22) + val innerTemperature = Temperature(20, Celsius) + + val thermalEnergyGain = + thermalHouse.calcThermalEnergyGain(Kilowatts(100), Seconds(3600)) + val thermalEnergyLoss = thermalHouse.calcThermalEnergyLoss( + innerTemperature, + Temperature(10, Celsius), + Seconds(3600), + ) + val thermalEnergyChange = thermalHouse.calcThermalEnergyChange( + thermalEnergyGain, + thermalEnergyLoss, + ) + val innerTemperatureChange = + thermalHouse.calcInnerTemperatureChange(thermalEnergyChange) + val newInnerTemperature = thermalHouse.calcNewInnerTemperature( + innerTemperature, + innerTemperatureChange, + ) + + thermalEnergyGain should approximate(KilowattHours(100)) + thermalEnergyLoss should approximate(KilowattHours(10)) + thermalEnergyChange should approximate(KilowattHours(90)) + innerTemperatureChange should approximate(Kelvin(9.0)) + newInnerTemperature should approximate(Celsius(29.0)) + } + + "Comprising function to calculate new inner temperature works as expected" in { + val thermalHouse = buildThermalHouse(18, 22) + val thermalPower = Kilowatts(100) + val duration = Seconds(3600) + val currentInnerTemperature = Temperature(20, Celsius) + val ambientTemperature = Temperature(10, Celsius) + + val newInnerTemperature = thermalHouse.newInnerTemperature( + thermalPower, + duration, + currentInnerTemperature, + ambientTemperature, + ) + + newInnerTemperature should approximate(Temperature(29, Celsius)) + } + + "Check build method" in { + val thermalHouseInput = new ThermalHouseInput( + UUID.randomUUID(), + "Thermal House", + null, + getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), + getQuantity(2741.5, StandardUnits.HEAT_CAPACITY), + getQuantity(0, CELSIUS), // stub + getQuantity(18, CELSIUS), + getQuantity(22, CELSIUS), + ) + + val thermalHouse = buildThermalHouse(18, 22) + + thermalHouse.id shouldBe thermalHouseInput.getId + thermalHouse.operatorInput shouldBe thermalHouseInput.getOperator + thermalHouse.operationTime shouldBe thermalHouseInput.getOperationTime + thermalHouse.bus shouldBe thermalHouseInput.getThermalBus + thermalHouse.ethLosses.toWattsPerKelvin shouldBe (thermalHouseInput.getEthLosses + .to(StandardUnits.THERMAL_TRANSMISSION) + .getValue + .doubleValue * 1000) + (thermalHouse.ethCapa * Temperature( + 1, + Celsius, + )).toKilowattHours shouldBe thermalHouseInput.getEthCapa + .to(StandardUnits.HEAT_CAPACITY) + .getValue + .doubleValue + thermalHouse.lowerBoundaryTemperature shouldBe Temperature(18, Celsius) + thermalHouse.upperBoundaryTemperature shouldBe Temperature(22, Celsius) + } + } +} From 8208772de1506fbaeb63b49448b9e75a26e22fb7 Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Fri, 2 Aug 2024 17:34:38 +0200 Subject: [PATCH 2/6] Simplify code with ThermalHouseTestData.scala --- .../scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala index 85659fc7f4..190eb0919b 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -18,7 +18,7 @@ import tech.units.indriya.unit.Units.CELSIUS import java.util.UUID -class ThermalHouseSpec extends UnitSpec { +class ThermalHouseSpec extends UnitSpec with ThermalHouseTestData { implicit val tolerance: Temperature = Celsius(0.0001) implicit val energyTolerance: Energy = KilowattHours(0.0001) From 8d490f31371e2ec1a2f2616da886ce529df293ac Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Tue, 6 Aug 2024 14:26:13 +0200 Subject: [PATCH 3/6] Using HpInputTestData to simplify the code and table instead of seq. remove unused code. fmt --- .../model/thermal/ThermalHouseSpec.scala | 44 +++++-------------- .../test/common/input/HpInputTestData.scala | 2 +- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala index 190eb0919b..0c59b5868e 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -7,44 +7,32 @@ package edu.ie3.simona.model.thermal import edu.ie3.datamodel.models.StandardUnits -import edu.ie3.datamodel.models.input.thermal.ThermalHouseInput import edu.ie3.simona.test.common.UnitSpec +import edu.ie3.simona.test.common.input.HpInputTestData +import org.scalatest.prop.TableFor3 import squants.energy._ import squants.thermal._ import squants.time._ import squants.{Energy, Temperature} -import tech.units.indriya.quantity.Quantities.getQuantity -import tech.units.indriya.unit.Units.CELSIUS -import java.util.UUID +class ThermalHouseSpec extends UnitSpec with HpInputTestData { -class ThermalHouseSpec extends UnitSpec with ThermalHouseTestData { - - implicit val tolerance: Temperature = Celsius(0.0001) - implicit val energyTolerance: Energy = KilowattHours(0.0001) + implicit val tolerance: Temperature = Celsius(1e-4) + implicit val energyTolerance: Energy = KilowattHours(1e-4) def buildThermalHouse( lowerBoundaryTemperature: Double, upperBoundaryTemperature: Double, ): ThermalHouse = { - val thermalHouseInput = new ThermalHouseInput( - UUID.randomUUID(), - "Thermal House", - null, - getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), - getQuantity(10.0, StandardUnits.HEAT_CAPACITY), - getQuantity(0, CELSIUS), // stub - getQuantity(upperBoundaryTemperature, CELSIUS), - getQuantity(lowerBoundaryTemperature, CELSIUS), - ) - ThermalHouse(thermalHouseInput) + thermalHouse(lowerBoundaryTemperature, upperBoundaryTemperature) } "ThermalHouse" should { "Functions testing inner temperature work as expected" in { val thermalHouse = buildThermalHouse(18, 22) - val testCases = Seq( + val testCases: TableFor3[Double, Boolean, Boolean] = Table( + ("Inner Temperature (°C)", "Is Too High", "Is Too Low"), (17d, false, true), (17.98d, false, true), (18d, false, true), @@ -57,10 +45,7 @@ class ThermalHouseSpec extends UnitSpec with ThermalHouseTestData { testCases.foreach { case (innerTemperature, isTooHigh, isTooLow) => val innerTemp = Temperature(innerTemperature, Celsius) val isHigher = thermalHouse.isInnerTemperatureTooHigh(innerTemp) - val isLower = thermalHouse.isInnerTemperatureTooLow( - innerTemp, - thermalHouse.lowerBoundaryTemperature, - ) + val isLower = thermalHouse.isInnerTemperatureTooLow(innerTemp) isHigher shouldBe isTooHigh isLower shouldBe isTooLow @@ -114,18 +99,9 @@ class ThermalHouseSpec extends UnitSpec with ThermalHouseTestData { } "Check build method" in { - val thermalHouseInput = new ThermalHouseInput( - UUID.randomUUID(), - "Thermal House", - null, - getQuantity(1.0, StandardUnits.THERMAL_TRANSMISSION), - getQuantity(2741.5, StandardUnits.HEAT_CAPACITY), - getQuantity(0, CELSIUS), // stub - getQuantity(18, CELSIUS), - getQuantity(22, CELSIUS), - ) val thermalHouse = buildThermalHouse(18, 22) + val thermalHouseInput = defaultThermalHouse thermalHouse.id shouldBe thermalHouseInput.getId thermalHouse.operatorInput shouldBe thermalHouseInput.getOperator diff --git a/src/test/scala/edu/ie3/simona/test/common/input/HpInputTestData.scala b/src/test/scala/edu/ie3/simona/test/common/input/HpInputTestData.scala index 2611073a1c..4c5a48dfd1 100644 --- a/src/test/scala/edu/ie3/simona/test/common/input/HpInputTestData.scala +++ b/src/test/scala/edu/ie3/simona/test/common/input/HpInputTestData.scala @@ -68,7 +68,7 @@ trait HpInputTestData extends NodeInputTestData with ThermalGridTestData { ) protected val defaultThermalHouse = new ThermalHouseInput( UUID.fromString("91940626-bdd0-41cf-96dd-47c94c86b20e"), - "thermal house", + "Thermal house", thermalBusInput, Quantities.getQuantity(0.325, StandardUnits.THERMAL_TRANSMISSION), Quantities.getQuantity(75, StandardUnits.HEAT_CAPACITY), From 10c651c7d30f40fe98c426eb84f403e0ca9ae0e5 Mon Sep 17 00:00:00 2001 From: danielfeismann Date: Tue, 6 Aug 2024 16:08:57 +0200 Subject: [PATCH 4/6] Updated dependabot reviewers --- .github/dependabot.yml | 2 +- CHANGELOG.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 349dacd365..a16766cf6b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -9,9 +9,9 @@ updates: target-branch: dev reviewers: - t-ober - - sensarmad - sebastian-peter - danielfeismann + - jo-bao ignore: - dependency-name: org.scalatest:scalatest_2.13 versions: diff --git a/CHANGELOG.md b/CHANGELOG.md index 468de1d410..14cb780d95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Rewrote SystemComponentTest from groovy to scala [#646](https://github.com/ie3-institute/simona/issues/646) - Converting remaining rst files to markdown [#838](https://github.com/ie3-institute/simona/issues/838) - Merging both `FixedFeedInModelSpec` tests [#870](https://github.com/ie3-institute/simona/issues/870) +- Updated dependabot reviewers [#888](https://github.com/ie3-institute/simona/issues/888) ### Fixed - Removed a repeated line in the documentation of vn_simona config [#658](https://github.com/ie3-institute/simona/issues/658) From 6717ae10b9284bc136f501b8806e51b2619437ed Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Wed, 7 Aug 2024 20:10:18 +0200 Subject: [PATCH 5/6] Fix "Check build method", remove def buildThermalHouse ,Codacy,fmt --- .../model/thermal/ThermalHouseSpec.scala | 65 +++++++++---------- 1 file changed, 29 insertions(+), 36 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala index 0c59b5868e..cddda378de 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -6,7 +6,6 @@ package edu.ie3.simona.model.thermal -import edu.ie3.datamodel.models.StandardUnits import edu.ie3.simona.test.common.UnitSpec import edu.ie3.simona.test.common.input.HpInputTestData import org.scalatest.prop.TableFor3 @@ -20,19 +19,13 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { implicit val tolerance: Temperature = Celsius(1e-4) implicit val energyTolerance: Energy = KilowattHours(1e-4) - def buildThermalHouse( - lowerBoundaryTemperature: Double, - upperBoundaryTemperature: Double, - ): ThermalHouse = { - thermalHouse(lowerBoundaryTemperature, upperBoundaryTemperature) - } - "ThermalHouse" should { "Functions testing inner temperature work as expected" in { - val thermalHouse = buildThermalHouse(18, 22) + + val thermalHouseTest = thermalHouse(18, 22) val testCases: TableFor3[Double, Boolean, Boolean] = Table( - ("Inner Temperature (°C)", "Is Too High", "Is Too Low"), + ("Inner Temperature (C)", "Is Too High", "Is Too Low"), (17d, false, true), (17.98d, false, true), (18d, false, true), @@ -44,8 +37,8 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { testCases.foreach { case (innerTemperature, isTooHigh, isTooLow) => val innerTemp = Temperature(innerTemperature, Celsius) - val isHigher = thermalHouse.isInnerTemperatureTooHigh(innerTemp) - val isLower = thermalHouse.isInnerTemperatureTooLow(innerTemp) + val isHigher = thermalHouseTest.isInnerTemperatureTooHigh(innerTemp) + val isLower = thermalHouseTest.isInnerTemperatureTooLow(innerTemp) isHigher shouldBe isTooHigh isLower shouldBe isTooLow @@ -53,23 +46,23 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { } "Calculation of thermal energy change and new inner temperature is performed correctly" in { - val thermalHouse = buildThermalHouse(18, 22) + val thermalHouseTest = thermalHouse(18, 22) val innerTemperature = Temperature(20, Celsius) val thermalEnergyGain = - thermalHouse.calcThermalEnergyGain(Kilowatts(100), Seconds(3600)) - val thermalEnergyLoss = thermalHouse.calcThermalEnergyLoss( + thermalHouseTest.calcThermalEnergyGain(Kilowatts(100), Seconds(3600)) + val thermalEnergyLoss = thermalHouseTest.calcThermalEnergyLoss( innerTemperature, Temperature(10, Celsius), Seconds(3600), ) - val thermalEnergyChange = thermalHouse.calcThermalEnergyChange( + val thermalEnergyChange = thermalHouseTest.calcThermalEnergyChange( thermalEnergyGain, thermalEnergyLoss, ) val innerTemperatureChange = - thermalHouse.calcInnerTemperatureChange(thermalEnergyChange) - val newInnerTemperature = thermalHouse.calcNewInnerTemperature( + thermalHouseTest.calcInnerTemperatureChange(thermalEnergyChange) + val newInnerTemperature = thermalHouseTest.calcNewInnerTemperature( innerTemperature, innerTemperatureChange, ) @@ -82,13 +75,13 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { } "Comprising function to calculate new inner temperature works as expected" in { - val thermalHouse = buildThermalHouse(18, 22) + val thermalHouseTest = thermalHouse(18, 22) val thermalPower = Kilowatts(100) val duration = Seconds(3600) val currentInnerTemperature = Temperature(20, Celsius) val ambientTemperature = Temperature(10, Celsius) - val newInnerTemperature = thermalHouse.newInnerTemperature( + val newInnerTemperature = thermalHouseTest.newInnerTemperature( thermalPower, duration, currentInnerTemperature, @@ -100,26 +93,26 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { "Check build method" in { - val thermalHouse = buildThermalHouse(18, 22) + val thermalHouseTest = thermalHouse(18, 22) val thermalHouseInput = defaultThermalHouse - thermalHouse.id shouldBe thermalHouseInput.getId - thermalHouse.operatorInput shouldBe thermalHouseInput.getOperator - thermalHouse.operationTime shouldBe thermalHouseInput.getOperationTime - thermalHouse.bus shouldBe thermalHouseInput.getThermalBus - thermalHouse.ethLosses.toWattsPerKelvin shouldBe (thermalHouseInput.getEthLosses - .to(StandardUnits.THERMAL_TRANSMISSION) - .getValue - .doubleValue * 1000) - (thermalHouse.ethCapa * Temperature( + thermalHouseTest.id shouldBe thermalHouseInput.getId + thermalHouseTest.operatorInput shouldBe thermalHouseInput.getOperator + thermalHouseTest.operationTime shouldBe thermalHouseInput.getOperationTime + thermalHouseTest.bus shouldBe null + thermalHouseTest.ethLosses.toWattsPerKelvin shouldBe 1000.0 + (thermalHouseTest.ethCapa * Temperature( 1, Celsius, - )).toKilowattHours shouldBe thermalHouseInput.getEthCapa - .to(StandardUnits.HEAT_CAPACITY) - .getValue - .doubleValue - thermalHouse.lowerBoundaryTemperature shouldBe Temperature(18, Celsius) - thermalHouse.upperBoundaryTemperature shouldBe Temperature(22, Celsius) + )).toKilowattHours shouldBe 2741.5 + thermalHouseTest.lowerBoundaryTemperature shouldBe Temperature( + 18, + Celsius, + ) + thermalHouseTest.upperBoundaryTemperature shouldBe Temperature( + 22, + Celsius, + ) } } } From 4a15728d82ac804d66db9e841d87de5871b89429 Mon Sep 17 00:00:00 2001 From: pierrepetersmeier Date: Fri, 9 Aug 2024 12:21:07 +0200 Subject: [PATCH 6/6] Fix "Check build method" --- .../model/thermal/ThermalHouseSpec.scala | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala index cddda378de..56e1cac144 100644 --- a/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala +++ b/src/test/scala/edu/ie3/simona/model/thermal/ThermalHouseSpec.scala @@ -8,6 +8,7 @@ package edu.ie3.simona.model.thermal import edu.ie3.simona.test.common.UnitSpec import edu.ie3.simona.test.common.input.HpInputTestData +import edu.ie3.util.scala.quantities.WattsPerKelvin import org.scalatest.prop.TableFor3 import squants.energy._ import squants.thermal._ @@ -93,25 +94,29 @@ class ThermalHouseSpec extends UnitSpec with HpInputTestData { "Check build method" in { - val thermalHouseTest = thermalHouse(18, 22) + val thermalTestHouse = thermalHouse(18, 22) val thermalHouseInput = defaultThermalHouse - thermalHouseTest.id shouldBe thermalHouseInput.getId - thermalHouseTest.operatorInput shouldBe thermalHouseInput.getOperator - thermalHouseTest.operationTime shouldBe thermalHouseInput.getOperationTime - thermalHouseTest.bus shouldBe null - thermalHouseTest.ethLosses.toWattsPerKelvin shouldBe 1000.0 - (thermalHouseTest.ethCapa * Temperature( + thermalTestHouse.id shouldBe thermalHouseInput.getId + thermalTestHouse.operatorInput shouldBe thermalHouseInput.getOperator + thermalTestHouse.operationTime shouldBe thermalHouseInput.getOperationTime + thermalTestHouse.bus shouldBe null + thermalTestHouse.ethLosses shouldBe WattsPerKelvin(1000.0) + (thermalTestHouse.ethCapa * Temperature( 1, - Celsius, - )).toKilowattHours shouldBe 2741.5 - thermalHouseTest.lowerBoundaryTemperature shouldBe Temperature( - 18, - Celsius, + Kelvin, + )) shouldBe KilowattHours(10.0) + thermalTestHouse.lowerBoundaryTemperature should approximate( + Temperature( + 18, + Celsius, + ) ) - thermalHouseTest.upperBoundaryTemperature shouldBe Temperature( - 22, - Celsius, + thermalTestHouse.upperBoundaryTemperature should approximate( + Temperature( + 22, + Celsius, + ) ) } }