Skip to content

Commit 7d78ffa

Browse files
Add tests for min max operations
Signed-off-by: Matthias Wende <[email protected]>
1 parent 892ba17 commit 7d78ffa

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

tests/timeseries/_formula_engine/test_formula_composition.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,51 @@ async def test_formula_composition_missing_bat(self, mocker: MockerFixture) -> N
170170

171171
assert count == 10
172172

173+
async def test_formula_composition_min_max(self, mocker: MockerFixture) -> None:
174+
"""Test the composition of formulas with min/max values."""
175+
mockgrid = MockMicrogrid(grid_meter=True)
176+
await mockgrid.start(mocker)
177+
178+
logical_meter = microgrid.logical_meter()
179+
engine_min = logical_meter.grid_power._min( # pylint: disable=protected-access
180+
Power.zero()
181+
).build("grid_power_min")
182+
engine_min_rx = engine_min.new_receiver()
183+
engine_max = logical_meter.grid_power._max( # pylint: disable=protected-access
184+
Power.zero()
185+
).build("grid_power_max")
186+
engine_max_rx = engine_max.new_receiver()
187+
188+
await mockgrid.mock_resampler.send_meter_power([100.0])
189+
190+
# Test min
191+
min_pow = await engine_min_rx.receive()
192+
assert min_pow and min_pow.value and min_pow.value.isclose(Power.zero())
193+
194+
# Test max
195+
max_pow = await engine_max_rx.receive()
196+
assert (
197+
max_pow and max_pow.value and max_pow.value.isclose(Power.from_watts(100.0))
198+
)
199+
200+
await mockgrid.mock_resampler.send_meter_power([-100.0])
201+
202+
# Test min
203+
min_pow = await engine_min_rx.receive()
204+
assert (
205+
min_pow
206+
and min_pow.value
207+
and min_pow.value.isclose(Power.from_watts(-100.0))
208+
)
209+
210+
# Test max
211+
max_pow = await engine_max_rx.receive()
212+
assert max_pow and max_pow.value and max_pow.value.isclose(Power.zero())
213+
214+
await engine_min._stop() # pylint: disable=protected-access
215+
await mockgrid.cleanup()
216+
await logical_meter.stop()
217+
173218
async def test_formula_composition_constant(self, mocker: MockerFixture) -> None:
174219
"""Test the composition of formulas with constant values."""
175220
mockgrid = MockMicrogrid(grid_meter=True)

0 commit comments

Comments
 (0)