Skip to content

Commit

Permalink
Merge branch 'df/#878-thermalGridIT' into df/#856-tap-water
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/scala/edu/ie3/simona/model/thermal/ThermalGrid.scala
  • Loading branch information
danielfeismann committed Jan 16, 2025
2 parents fcb9db4 + 14d49fc commit bef411e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed SonarQube quality gate using the correct parameter '-Dsonar.qualitygate.wait=true' [#1072](https://github.com/ie3-institute/simona/issues/1072)
- Updated `simonaAPI` to version `0.6.0` [#1080](https://github.com/ie3-institute/simona/issues/1080)
- Enhanced title in `CITATION.cff` [#1088](https://github.com/ie3-institute/simona/issues/1088)
- Refactor ThermalEnergyDemand definitions [#917](https://github.com/ie3-institute/simona/issues/917)

### Fixed
- Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505)
Expand Down
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 @@ -1484,7 +1484,7 @@ object ThermalGrid {

def hasRequiredDemand: Boolean = required > zeroKWh

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

Expand All @@ -1505,10 +1505,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
39 changes: 27 additions & 12 deletions src/test/scala/edu/ie3/simona/model/thermal/ThermalGridSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,13 @@ 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)

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."
}

"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."
}.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 {
Expand Down Expand Up @@ -89,7 +80,31 @@ class ThermalGridSpec
val possible = MegawattHours(0d)
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."
}.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 cannot be negative. 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 cannot be negative. 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 cannot be negative. This is not supported."
}

"return proper information, if required and additional demand is apparent" in {
Expand Down

0 comments on commit bef411e

Please sign in to comment.