Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/ps/#1061-SonarLink' into ps/#1061-…
Browse files Browse the repository at this point in the history
…SonarLink
  • Loading branch information
PhilippSchmelter committed Dec 12, 2024
2 parents 9e0d295 + 4133310 commit 4b51ff3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 65 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ jobs:
echo "SonarQube URL for Branch: $SONAR_STATUS_URL"
fi
branch_name="${{ env.branch_name }}"
TEST_SONAR_STATUS_URL="${BASE_SONAR_STATUS_URL}&branch=$branch_name"
echo "Testing: SonarQube URL for Branch: $TEST_SONAR_STATUS_URL"
QUALITY_GATE_STATUS=$(curl -s -u "${{ secrets.SONAR_TOKEN }}:" "$SONAR_STATUS_URL" | jq -r '.projectStatus.status')
echo "Quality Gate Status: $QUALITY_GATE_STATUS"
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Refactoring to only use 'lastHpState' and 'relevantData' for 'ThermalGrid' calculations [#916](https://github.com/ie3-institute/simona/issues/916)
- Refactor thermal calcRelevantData [#1051](https://github.com/ie3-institute/simona/issues/1051)
- Removed Deployment stage from Jenkinsfile [#1063](https://github.com/ie3-institute/simona/issues/1063)
- Prepare 'ChpModelSpec' and 'CylindricalThermalStorageSpec' for Storage without storageVolumeLvlMin [#1012](https://github.com/ie3-institute/simona/issues/1012)

### Fixed
- Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ trait MutableStorage {
* @return
* lack
*/
@deprecated("Use thermal storage state instead")
def tryToTakeAndReturnLack(
takenEnergy: Energy
): Option[Energy]
Expand Down
113 changes: 59 additions & 54 deletions src/test/scala/edu/ie3/simona/model/participant/ChpModelSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ChpModelSpec
val chpStateNotRunning: ChpState =
ChpState(isRunning = false, 0, Kilowatts(0), KilowattHours(0))
val chpStateRunning: ChpState =
ChpState(isRunning = true, 0, Kilowatts(0), KilowattHours(0))
ChpState(isRunning = true, 0, Kilowatts(42), KilowattHours(42))

val (storageInput, chpInput) = setupSpec()

Expand All @@ -62,7 +62,7 @@ class ChpModelSpec
"ThermalStorage",
thermalBus,
getQuantity(100, StandardUnits.VOLUME),
getQuantity(20, StandardUnits.VOLUME),
getQuantity(0, StandardUnits.VOLUME),
getQuantity(30, StandardUnits.TEMPERATURE),
getQuantity(40, StandardUnits.TEMPERATURE),
getQuantity(1.15, StandardUnits.SPECIFIC_HEAT_CAPACITY),
Expand Down Expand Up @@ -145,26 +145,26 @@ class ChpModelSpec
"Check active power after calculating next state with #chpState and heat demand #heatDemand kWh:" in {
val testCases = Table(
("chpState", "storageLvl", "heatDemand", "expectedActivePower"),
(chpStateNotRunning, 90, 0, 0), // tests case (false, false, true)
(chpStateNotRunning, 70, 0, 0), // tests case (false, false, true)
(
chpStateNotRunning,
90,
70,
8 * 115,
95,
), // tests case (false, true, false)
(chpStateNotRunning, 90, 10, 0), // tests case (false, true, true)
(chpStateRunning, 90, 0, 95), // tests case (true, false, true)
(chpStateRunning, 90, 8 * 115, 95), // tests case (true, true, false)
(chpStateRunning, 90, 10, 95), // tests case (true, true, true)
(chpStateNotRunning, 70, 10, 0), // tests case (false, true, true)
(chpStateRunning, 70, 0, 95), // tests case (true, false, true)
(chpStateRunning, 70, 8 * 115, 95), // tests case (true, true, false)
(chpStateRunning, 70, 10, 95), // tests case (true, true, true)
(
chpStateRunning,
90,
70,
7 * 115 + 1,
95,
), // test case (_, true, false) and demand covered together with chp
(
chpStateRunning,
90,
70,
9 * 115,
95,
), // test case (_, true, false) and demand not covered together with chp
Expand All @@ -190,26 +190,26 @@ class ChpModelSpec
"Check total energy after calculating next state with #chpState and heat demand #heatDemand kWh:" in {
val testCases = Table(
("chpState", "storageLvl", "heatDemand", "expectedTotalEnergy"),
(chpStateNotRunning, 90, 0, 0), // tests case (false, false, true)
(chpStateNotRunning, 70, 0, 0), // tests case (false, false, true)
(
chpStateNotRunning,
90,
70,
8 * 115,
100,
), // tests case (false, true, false)
(chpStateNotRunning, 90, 10, 0), // tests case (false, true, true)
(chpStateRunning, 90, 0, 100), // tests case (true, false, true)
(chpStateRunning, 90, 8 * 115, 100), // tests case (true, true, false)
(chpStateRunning, 90, 10, 100), // tests case (true, true, true)
(chpStateNotRunning, 70, 10, 0), // tests case (false, true, true)
(chpStateRunning, 70, 0, 100), // tests case (true, false, true)
(chpStateRunning, 70, 8 * 115, 100), // tests case (true, true, false)
(chpStateRunning, 70, 10, 100), // tests case (true, true, true)
(
chpStateRunning,
90,
70,
7 * 115 + 1,
100,
), // test case (_, true, false) and demand covered together with chp
(
chpStateRunning,
90,
70,
9 * 115,
100,
), // test case (_, true, false) and demand not covered together with chp
Expand All @@ -236,35 +236,35 @@ class ChpModelSpec
"Check storage level after calculating next state with #chpState and heat demand #heatDemand kWh:" in {
val testCases = Table(
("chpState", "storageLvl", "heatDemand", "expectedStoredEnergy"),
(chpStateNotRunning, 90, 0, 1035), // tests case (false, false, true)
(chpStateNotRunning, 70, 0, 805), // tests case (false, false, true)
(
chpStateNotRunning,
90,
70,
8 * 115,
230,
0,
), // tests case (false, true, false)
(chpStateNotRunning, 90, 10, 1025), // tests case (false, true, true)
(chpStateRunning, 90, 0, 1135), // tests case (true, false, true)
(chpStateRunning, 90, 8 * 115, 230), // tests case (true, true, false)
(chpStateRunning, 90, 10, 1125), // tests case (true, true, true)
(chpStateNotRunning, 70, 10, 795), // tests case (false, true, true)
(chpStateRunning, 70, 0, 905), // tests case (true, false, true)
(chpStateRunning, 70, 8 * 115, 0), // tests case (true, true, false)
(chpStateRunning, 70, 10, 895), // tests case (true, true, true)
(
chpStateRunning,
90,
70,
806,
329,
99,
), // test case (_, true, false) and demand covered together with chp
(
chpStateRunning,
90,
70,
9 * 115,
230,
0,
), // test case (_, true, false) and demand not covered together with chp
(
chpStateRunning,
92,
1,
1150,
), // test case (true, true, true) and storage volume exceeds maximum
), // test case (true, true, true) CHP running, storage at lvl 92 (1058 kWh) + 100 kWh from CHP exceeds max capacity (1150 kWh).
)

forAll(testCases) {
Expand All @@ -281,48 +281,54 @@ class ChpModelSpec
}

"Check time tick and running status after calculating next state with #chpState and heat demand #heatDemand kWh:" in {
val testCases = Seq(
// (ChpState, Storage Level, Heat Demand, Expected Time Tick, Expected Running Status)
val testCases = Table(
(
"chpState",
"storageLvl",
"heatDemand",
"expectedTick",
"expectedRunningStatus",
),
(
chpStateNotRunning,
90,
70,
0,
7200,
false,
), // Test case (false, false, true)
(
chpStateNotRunning,
90,
70,
8 * 115,
7200,
true,
), // Test case (false, true, false)
(
chpStateNotRunning,
90,
70,
10,
7200,
false,
), // Test case (false, true, true)
(chpStateRunning, 90, 0, 7200, true), // Test case (true, false, true)
(chpStateRunning, 70, 0, 7200, true), // Test case (true, false, true)
(
chpStateRunning,
90,
70,
8 * 115,
7200,
true,
), // Test case (true, true, false)
(chpStateRunning, 90, 10, 7200, true), // Test case (true, true, true)
(chpStateRunning, 70, 10, 7200, true), // Test case (true, true, true)
(
chpStateRunning,
90,
70,
806,
7200,
true,
), // Test case (_, true, false) and demand covered together with chp
(
chpStateRunning,
90,
70,
9 * 115,
7200,
true,
Expand All @@ -336,23 +342,22 @@ class ChpModelSpec
), // Test case (true, true, true) and storage volume exceeds maximum
)

for (
forAll(testCases) {
(
chpState,
storageLvl,
heatDemand,
expectedTimeTick,
expectedRunningStatus,
) <- testCases
) {
val chpData = buildChpRelevantData(chpState, heatDemand)
val thermalStorage = buildThermalStorage(storageInput, storageLvl)
val chpModel = buildChpModel(thermalStorage)
chpState,
storageLvl,
heatDemand,
expectedTick,
expectedRunningStatus,
) =>
val chpData = buildChpRelevantData(chpState, heatDemand)
val thermalStorage = buildThermalStorage(storageInput, storageLvl)
val chpModel = buildChpModel(thermalStorage)

val nextState = chpModel.calculateNextState(chpData)
val nextState = chpModel.calculateNextState(chpData)

nextState.lastTimeTick shouldEqual expectedTimeTick
nextState.isRunning shouldEqual expectedRunningStatus
nextState.lastTimeTick shouldEqual expectedTick
nextState.isRunning shouldEqual expectedRunningStatus
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class CylindricalThermalStorageSpec
"ThermalStorage",
null,
getQuantity(100, StandardUnits.VOLUME),
getQuantity(20, StandardUnits.VOLUME),
getQuantity(0, StandardUnits.VOLUME),
getQuantity(30, StandardUnits.TEMPERATURE),
getQuantity(40, StandardUnits.TEMPERATURE),
getQuantity(1.15, StandardUnits.SPECIFIC_HEAT_CAPACITY),
Expand Down Expand Up @@ -92,7 +92,7 @@ class CylindricalThermalStorageSpec
storage.tryToStoreAndReturnRemainder(vol2Energy(CubicMeters(55)))
val newLevel2 = storage._storedEnergy
val isCovering = storage.isDemandCoveredByStorage(KilowattHours(5))
val lack = storage.tryToTakeAndReturnLack(vol2Energy(CubicMeters(95)))
val lack = storage.tryToTakeAndReturnLack(vol2Energy(CubicMeters(115)))
val newLevel3 = storage._storedEnergy
val notCovering = storage.isDemandCoveredByStorage(KilowattHours(1))

Expand All @@ -101,7 +101,7 @@ class CylindricalThermalStorageSpec
surplus.value shouldBe vol2Energy(CubicMeters(5))
newLevel2 should approximate(vol2Energy(CubicMeters(100)))
lack.value shouldBe vol2Energy(CubicMeters(15))
newLevel3 should approximate(vol2Energy(CubicMeters(20)))
newLevel3 should approximate(vol2Energy(CubicMeters(0)))
isCovering shouldBe true
notCovering shouldBe false
}
Expand All @@ -110,7 +110,7 @@ class CylindricalThermalStorageSpec
val storage = buildThermalStorage(storageInput, CubicMeters(70))

val usableThermalEnergy = storage.usableThermalEnergy
usableThermalEnergy should approximate(KilowattHours(5 * 115))
usableThermalEnergy should approximate(KilowattHours(805))
}

"Apply, validation, and build method work correctly" in {
Expand Down Expand Up @@ -145,11 +145,11 @@ class CylindricalThermalStorageSpec
),
(
0L,
250.0,
20.0,
10.0,
3600L,
-42.0,
260.0,
30.0,
ThermalStorage.ThermalStorageThreshold.StorageEmpty(6171L),
),
(
Expand All @@ -163,11 +163,11 @@ class CylindricalThermalStorageSpec
),
(
0L,
250.0,
20.0,
-10.0,
3600L,
-42.0,
240.0,
10.0,
ThermalStorage.ThermalStorageThreshold.StorageEmpty(4457L),
),
(
Expand All @@ -181,11 +181,11 @@ class CylindricalThermalStorageSpec
),
(
0L,
240.0,
10.0,
-9.0,
3600L,
-5000.0,
231.0,
1.0,
ThermalStorage.ThermalStorageThreshold.StorageEmpty(3601L),
),
)
Expand Down Expand Up @@ -232,7 +232,7 @@ class CylindricalThermalStorageSpec
"expectedStoredEnergy",
),
(0L, 250.0, 10.0, 3600L, 0.0, 260.0),
(0L, 250.0, -10.0, 3600L, 0.0, 240.0),
(0L, 20.0, -10.0, 3600L, 0.0, 10.0),
)

forAll(cases) {
Expand Down

0 comments on commit 4b51ff3

Please sign in to comment.