summaryrefslogtreecommitdiff
path: root/opendc-simulator/opendc-simulator-power/src
diff options
context:
space:
mode:
Diffstat (limited to 'opendc-simulator/opendc-simulator-power/src')
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt150
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt167
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt110
-rw-r--r--opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt5
4 files changed, 226 insertions, 206 deletions
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
index f596ca4e..9df72c49 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPduTest.kt
@@ -34,94 +34,100 @@ import org.opendc.simulator.kotlin.runSimulation
*/
internal class SimPduTest {
@Test
- fun testZeroOutlets() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
+ fun testZeroOutlets() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val pdu = SimPdu(graph)
+ source.connect(pdu)
- yield()
+ yield()
- assertEquals(0.0f, source.powerDraw)
- }
+ assertEquals(0.0f, source.powerDraw)
+ }
@Test
- fun testSingleOutlet() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(100.0f, source.powerDraw)
- }
+ fun testSingleOutlet() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val pdu = SimPdu(graph)
+ source.connect(pdu)
+ pdu.newOutlet().connect(TestInlet(graph))
+
+ yield()
+
+ assertEquals(100.0f, source.powerDraw)
+ }
@Test
- fun testDoubleOutlet() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 200.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
+ fun testDoubleOutlet() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 200.0f)
+ val pdu = SimPdu(graph)
+ source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
- pdu.newOutlet().connect(TestInlet(graph))
+ pdu.newOutlet().connect(TestInlet(graph))
+ pdu.newOutlet().connect(TestInlet(graph))
- yield()
+ yield()
- assertEquals(200.0f, source.powerDraw)
- }
+ assertEquals(200.0f, source.powerDraw)
+ }
@Test
- fun testDisconnect() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 300.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
-
- val outlet = pdu.newOutlet()
- outlet.connect(TestInlet(graph))
- outlet.disconnect()
+ fun testDisconnect() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 300.0f)
+ val pdu = SimPdu(graph)
+ source.connect(pdu)
+
+ val outlet = pdu.newOutlet()
+ outlet.connect(TestInlet(graph))
+ outlet.disconnect()
- yield()
+ yield()
- assertEquals(0.0f, source.powerDraw)
- }
+ assertEquals(0.0f, source.powerDraw)
+ }
@Test
- fun testLoss() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val pdu = SimPdu(graph, /*idlePower*/ 1.5f, /*lossCoefficient*/ 0.015f)
- source.connect(pdu)
- pdu.newOutlet().connect(TestInlet(graph))
-
- yield()
-
- assertEquals(251.5f, source.powerDraw, 0.01f)
- }
+ fun testLoss() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 500.0f)
+ // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
+ val pdu = SimPdu(graph, 1.5f, 0.015f)
+ source.connect(pdu)
+ pdu.newOutlet().connect(TestInlet(graph))
+
+ yield()
+
+ assertEquals(251.5f, source.powerDraw, 0.01f)
+ }
@Test
- fun testOutletClose() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val pdu = SimPdu(graph)
- source.connect(pdu)
- val outlet = pdu.newOutlet()
- outlet.close()
-
- yield()
-
- assertThrows<IllegalStateException> {
- outlet.connect(TestInlet(graph))
+ fun testOutletClose() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val pdu = SimPdu(graph)
+ source.connect(pdu)
+ val outlet = pdu.newOutlet()
+ outlet.close()
+
+ yield()
+
+ assertThrows<IllegalStateException> {
+ outlet.connect(TestInlet(graph))
+ }
}
- }
}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
index 03c942b4..bbc9ad92 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimPowerSourceTest.kt
@@ -41,108 +41,115 @@ import org.opendc.simulator.kotlin.runSimulation
*/
internal class SimPowerSourceTest {
@Test
- fun testInitialState() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
-
- yield()
-
- assertAll(
- { assertFalse(source.isConnected) },
- { assertNull(source.inlet) },
- { assertEquals(100.0f, source.capacity) }
- )
- }
+ fun testInitialState() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+
+ yield()
+
+ assertAll(
+ { assertFalse(source.isConnected) },
+ { assertNull(source.inlet) },
+ { assertEquals(100.0f, source.capacity) },
+ )
+ }
@Test
- fun testDisconnectIdempotent() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
-
- assertDoesNotThrow { source.disconnect() }
- assertFalse(source.isConnected)
- }
+ fun testDisconnectIdempotent() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+
+ assertDoesNotThrow { source.disconnect() }
+ assertFalse(source.isConnected)
+ }
@Test
- fun testConnect() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val inlet = TestInlet(graph)
+ fun testConnect() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val inlet = TestInlet(graph)
- source.connect(inlet)
+ source.connect(inlet)
- yield()
+ yield()
- assertAll(
- { assertTrue(source.isConnected) },
- { assertEquals(inlet, source.inlet) },
- { assertTrue(inlet.isConnected) },
- { assertEquals(source, inlet.outlet) },
- { assertEquals(100.0f, source.powerDraw) }
- )
- }
+ assertAll(
+ { assertTrue(source.isConnected) },
+ { assertEquals(inlet, source.inlet) },
+ { assertTrue(inlet.isConnected) },
+ { assertEquals(source, inlet.outlet) },
+ { assertEquals(100.0f, source.powerDraw) },
+ )
+ }
@Test
- fun testDisconnect() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val inlet = TestInlet(graph)
+ fun testDisconnect() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val inlet = TestInlet(graph)
- source.connect(inlet)
- source.disconnect()
+ source.connect(inlet)
+ source.disconnect()
- yield()
+ yield()
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
+ assertEquals(0.0f, inlet.flowOutlet.capacity)
+ }
@Test
- fun testDisconnectAssertion() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
+ fun testDisconnectAssertion() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns false
- every { inlet.flowOutlet } returns TestInlet(graph).flowOutlet
+ val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
+ every { inlet.isConnected } returns false
+ every { inlet.flowOutlet } returns TestInlet(graph).flowOutlet
- source.connect(inlet)
- inlet.outlet = null
+ source.connect(inlet)
+ inlet.outlet = null
- assertThrows<AssertionError> {
- source.disconnect()
+ assertThrows<AssertionError> {
+ source.disconnect()
+ }
}
- }
@Test
- fun testOutletAlreadyConnected() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val inlet = TestInlet(graph)
-
- source.connect(inlet)
- assertThrows<IllegalStateException> {
- source.connect(TestInlet(graph))
- }
+ fun testOutletAlreadyConnected() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val inlet = TestInlet(graph)
- assertEquals(inlet, source.inlet)
- }
+ source.connect(inlet)
+ assertThrows<IllegalStateException> {
+ source.connect(TestInlet(graph))
+ }
+
+ assertEquals(inlet, source.inlet)
+ }
@Test
- fun testInletAlreadyConnected() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 100.0f)
- val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
- every { inlet.isConnected } returns true
-
- assertThrows<IllegalStateException> {
- source.connect(inlet)
+ fun testInletAlreadyConnected() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 100.0f)
+ val inlet = mockk<SimPowerInlet>(relaxUnitFun = true)
+ every { inlet.isConnected } returns true
+
+ assertThrows<IllegalStateException> {
+ source.connect(inlet)
+ }
}
- }
}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
index 89fede63..cbd23887 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/SimUpsTest.kt
@@ -34,71 +34,75 @@ import org.opendc.simulator.kotlin.runSimulation
*/
internal class SimUpsTest {
@Test
- fun testSingleInlet() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 200.0f)
- val ups = SimUps(graph)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
+ fun testSingleInlet() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 200.0f)
+ val ups = SimUps(graph)
+ source.connect(ups.newInlet())
+ ups.connect(TestInlet(graph))
- yield()
+ yield()
- assertEquals(100.0f, source.powerDraw)
- }
+ assertEquals(100.0f, source.powerDraw)
+ }
@Test
- fun testDoubleInlet() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, /*capacity*/ 200.0f)
- val source2 = SimPowerSource(graph, /*capacity*/ 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
-
- ups.connect(TestInlet(graph))
-
- yield()
-
- assertAll(
- { assertEquals(50.0f, source1.powerDraw) },
- { assertEquals(50.0f, source2.powerDraw) }
- )
- }
+ fun testDoubleInlet() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source1 = SimPowerSource(graph, 200.0f)
+ val source2 = SimPowerSource(graph, 200.0f)
+ val ups = SimUps(graph)
+ source1.connect(ups.newInlet())
+ source2.connect(ups.newInlet())
+
+ ups.connect(TestInlet(graph))
+
+ yield()
+
+ assertAll(
+ { assertEquals(50.0f, source1.powerDraw) },
+ { assertEquals(50.0f, source2.powerDraw) },
+ )
+ }
@Test
- fun testLoss() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source = SimPowerSource(graph, /*capacity*/ 500.0f)
- // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
- val ups = SimUps(graph, /*idlePower*/ 4.0f, /*lossCoefficient*/ 0.05f)
- source.connect(ups.newInlet())
- ups.connect(TestInlet(graph))
+ fun testLoss() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source = SimPowerSource(graph, 500.0f)
+ // https://download.schneider-electric.com/files?p_Doc_Ref=SPD_NRAN-66CK3D_EN
+ val ups = SimUps(graph, 4.0f, 0.05f)
+ source.connect(ups.newInlet())
+ ups.connect(TestInlet(graph))
- yield()
+ yield()
- assertEquals(109.0f, source.powerDraw, 0.01f)
- }
+ assertEquals(109.0f, source.powerDraw, 0.01f)
+ }
@Test
- fun testDisconnect() = runSimulation {
- val engine = FlowEngine.create(dispatcher)
- val graph = engine.newGraph()
- val source1 = SimPowerSource(graph, /*capacity*/ 200.0f)
- val source2 = SimPowerSource(graph, /*capacity*/ 200.0f)
- val ups = SimUps(graph)
- source1.connect(ups.newInlet())
- source2.connect(ups.newInlet())
+ fun testDisconnect() =
+ runSimulation {
+ val engine = FlowEngine.create(dispatcher)
+ val graph = engine.newGraph()
+ val source1 = SimPowerSource(graph, 200.0f)
+ val source2 = SimPowerSource(graph, 200.0f)
+ val ups = SimUps(graph)
+ source1.connect(ups.newInlet())
+ source2.connect(ups.newInlet())
- val inlet = TestInlet(graph)
+ val inlet = TestInlet(graph)
- ups.connect(inlet)
- ups.disconnect()
+ ups.connect(inlet)
+ ups.disconnect()
- yield()
+ yield()
- assertEquals(0.0f, inlet.flowOutlet.capacity)
- }
+ assertEquals(0.0f, inlet.flowOutlet.capacity)
+ }
}
diff --git a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
index d5f509e7..1c06acf4 100644
--- a/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
+++ b/opendc-simulator/opendc-simulator-power/src/test/kotlin/org/opendc/simulator/power/TestInlet.kt
@@ -38,7 +38,10 @@ class TestInlet(graph: FlowGraph) : SimPowerInlet(), FlowStageLogic {
flowOutlet.push(100.0f)
}
- override fun onUpdate(ctx: FlowStage, now: Long): Long = Long.MAX_VALUE
+ override fun onUpdate(
+ ctx: FlowStage,
+ now: Long,
+ ): Long = Long.MAX_VALUE
override fun getFlowOutlet(): Outlet {
return flowOutlet