Skip to content

Commit

Permalink
Merge branch 'df/#930-refactor-handleInfeed' into df/#878-thermalGridIT
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
#	src/test/scala/edu/ie3/simona/model/thermal/ThermalGridSpec.scala
  • Loading branch information
danielfeismann committed Jan 16, 2025
2 parents 73e7778 + ff8feb5 commit 5d23ae5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ object ThermalGrid {

def hasRequiredDemand: Boolean = required > zeroMWh

def hasAdditionalDemand: Boolean = possible > zeroMWh
def hasAdditionalDemand: Boolean = possible > required
}
object ThermalEnergyDemand {

Expand All @@ -872,10 +872,15 @@ object ThermalGrid {
math.abs(possible.toKilowattHours) < math.abs(required.toKilowattHours)
)
throw new InvalidParameterException(
s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
s"The possible amount of energy $possible is smaller than the required amount of energy $required. This is not supported."
)
else
new ThermalEnergyDemand(required, possible)

if (possible.toKilowattHours < 0 || required.toKilowattHours < 0)
throw new InvalidParameterException(
s"The possible $possible or required $required amount of energy cannot be negative. This is not supported."
)

new ThermalEnergyDemand(required, possible)
}

def noDemand: ThermalEnergyDemand = ThermalEnergyDemand(
Expand Down
36 changes: 26 additions & 10 deletions src/test/scala/edu/ie3/simona/model/thermal/ThermalGridSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

package edu.ie3.simona.model.thermal

import edu.ie3.simona.exceptions.InvalidParameterException
import edu.ie3.datamodel.models.input.thermal.ThermalStorageInput
import edu.ie3.simona.exceptions.InvalidParameterException
import edu.ie3.simona.model.thermal.ThermalGrid.ThermalEnergyDemand
Expand All @@ -27,7 +28,7 @@ class ThermalGridSpec

"Testing the thermal energy demand" when {
"instantiating it from given values" should {
"throw exception for non-plausible input (positive)" in {
"throw exception for non-sensible input (positive)" in {
val possible = MegawattHours(40d)
val required = MegawattHours(42d)

Expand All @@ -36,15 +37,6 @@ class ThermalGridSpec
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

"throw exception for non-sensible input (negative)" in {
val possible = MegawattHours(-40d)
val required = MegawattHours(-42d)

intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

"set the correct values, if they are sensible" in {
val possible = MegawattHours(45d)
val required = MegawattHours(42d)
Expand Down Expand Up @@ -92,6 +84,30 @@ class ThermalGridSpec
}.getMessage shouldBe s"The possible amount of energy {$possible} is smaller than the required amount of energy {$required}. This is not supported."
}

"throw exception, if required demand is smaller than zero" in {
val required = MegawattHours(-2d)
val possible = MegawattHours(5d)
intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible {$possible} or required {$required} amount of energy is smaller than zero. This is not supported."
}

"throw exception, if possible demand is smaller than zero" in {
val required = MegawattHours(2d)
val possible = MegawattHours(-5d)
intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible {$possible} or required {$required} amount of energy is smaller than zero. This is not supported."
}

"throw exception, if possible and required demand are smaller than zero" in {
val required = MegawattHours(-2d)
val possible = MegawattHours(-5d)
intercept[InvalidParameterException] {
ThermalEnergyDemand(required, possible)
}.getMessage shouldBe s"The possible {$possible} or required {$required} amount of energy is smaller than zero. This is not supported."
}

"return proper information, if required and additional demand is apparent" in {
val required = MegawattHours(45d)
val possible = MegawattHours(47d)
Expand Down

0 comments on commit 5d23ae5

Please sign in to comment.