@@ -74,8 +74,11 @@ def bounds(
7474 assert report .inclusion_bounds .upper .as_watts () == expected_bounds [1 ]
7575
7676
77- async def test_matryoshka_algorithm () -> None : # pylint: disable=too-many-statements
78- """Tests for the power managing actor."""
77+ async def test_matryoshka_no_excl () -> None : # pylint: disable=too-many-statements
78+ """Tests for the power managing actor.
79+
80+ With just inclusion bounds, and no exclusion bounds.
81+ """
7982 batteries = frozenset ({2 , 5 })
8083
8184 system_bounds = battery_pool .PowerMetrics (
@@ -179,3 +182,162 @@ async def test_matryoshka_algorithm() -> None: # pylint: disable=too-many-state
179182
180183 tester .tgt_power (priority = 1 , power = None , bounds = (- 200 , 200 ), expected = 50.0 )
181184 tester .bounds (priority = 1 , expected_power = 50.0 , expected_bounds = (- 100.0 , 100.0 ))
185+
186+
187+ async def test_matryoshka_with_excl_1 () -> None :
188+ """Tests for the power managing actor.
189+
190+ With inclusion bounds, and exclusion bounds -30.0 to 0.0.
191+ """
192+ batteries = frozenset ({2 , 5 })
193+
194+ system_bounds = battery_pool .PowerMetrics (
195+ timestamp = datetime .now (tz = timezone .utc ),
196+ inclusion_bounds = timeseries .Bounds (
197+ lower = Power .from_watts (- 200.0 ), upper = Power .from_watts (200.0 )
198+ ),
199+ exclusion_bounds = timeseries .Bounds (
200+ lower = Power .from_watts (- 30.0 ), upper = Power .zero ()
201+ ),
202+ )
203+
204+ tester = StatefulTester (batteries , system_bounds )
205+
206+ tester .tgt_power (priority = 2 , power = 25.0 , bounds = (25.0 , 50.0 ), expected = 25.0 )
207+ tester .bounds (priority = 2 , expected_power = 25.0 , expected_bounds = (- 200.0 , 200.0 ))
208+ tester .bounds (priority = 1 , expected_power = 25.0 , expected_bounds = (25.0 , 50.0 ))
209+
210+ tester .tgt_power (priority = 1 , power = 20.0 , bounds = (20.0 , 50.0 ), expected = None )
211+ tester .bounds (priority = 1 , expected_power = 25.0 , expected_bounds = (25.0 , 50.0 ))
212+
213+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 10.0 , 50.0 ), expected = 20.0 )
214+ tester .bounds (priority = 1 , expected_power = 20.0 , expected_bounds = (0.0 , 50.0 ))
215+ tester .bounds (priority = 0 , expected_power = 20.0 , expected_bounds = (20.0 , 50.0 ))
216+
217+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , 50.0 ), expected = 0.0 )
218+ tester .bounds (priority = 0 , expected_power = 0.0 , expected_bounds = (0.0 , 50.0 ))
219+
220+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , 20.0 ), expected = None )
221+ tester .bounds (priority = 0 , expected_power = 0.0 , expected_bounds = (0.0 , 20.0 ))
222+
223+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , - 5.0 ), expected = None )
224+ tester .bounds (priority = 0 , expected_power = 0.0 , expected_bounds = (0.0 , 50.0 ))
225+
226+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 200.0 , - 5.0 ), expected = - 30.0 )
227+ tester .bounds (priority = 1 , expected_power = - 30.0 , expected_bounds = (- 200.0 , - 30.0 ))
228+ tester .bounds (priority = 0 , expected_power = - 30.0 , expected_bounds = (- 200.0 , - 30.0 ))
229+
230+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 100.0 , - 5.0 ), expected = None )
231+ tester .bounds (priority = 0 , expected_power = - 30.0 , expected_bounds = (- 100.0 , - 30.0 ))
232+
233+ tester .tgt_power (priority = 1 , power = - 40.0 , bounds = (- 100.0 , - 35.0 ), expected = - 40.0 )
234+ tester .bounds (priority = 0 , expected_power = - 40.0 , expected_bounds = (- 100.0 , - 35.0 ))
235+
236+
237+ async def test_matryoshka_with_excl_2 () -> None :
238+ """Tests for the power managing actor.
239+
240+ With inclusion bounds, and exclusion bounds 0.0 to 30.0.
241+ """
242+ batteries = frozenset ({2 , 5 })
243+
244+ system_bounds = battery_pool .PowerMetrics (
245+ timestamp = datetime .now (tz = timezone .utc ),
246+ inclusion_bounds = timeseries .Bounds (
247+ lower = Power .from_watts (- 200.0 ), upper = Power .from_watts (200.0 )
248+ ),
249+ exclusion_bounds = timeseries .Bounds (
250+ lower = Power .zero (), upper = Power .from_watts (30.0 )
251+ ),
252+ )
253+
254+ tester = StatefulTester (batteries , system_bounds )
255+
256+ tester .tgt_power (priority = 2 , power = 25.0 , bounds = (25.0 , 50.0 ), expected = 30.0 )
257+ tester .bounds (priority = 2 , expected_power = 30.0 , expected_bounds = (- 200.0 , 200.0 ))
258+ tester .bounds (priority = 1 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
259+
260+ tester .tgt_power (priority = 1 , power = 20.0 , bounds = (20.0 , 50.0 ), expected = None )
261+ tester .bounds (priority = 1 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
262+
263+ tester .tgt_power (priority = 1 , power = 10.0 , bounds = (5.0 , 10.0 ), expected = None )
264+ tester .bounds (priority = 0 , expected_power = 30.0 , expected_bounds = (30 , 50.0 ))
265+
266+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 10.0 , 50.0 ), expected = 0.0 )
267+ tester .bounds (priority = 1 , expected_power = 0.0 , expected_bounds = (- 10.0 , 50.0 ))
268+ tester .bounds (priority = 0 , expected_power = 0.0 , expected_bounds = (- 10.0 , 50.0 ))
269+
270+ tester .tgt_power (priority = 0 , power = 40 , bounds = (None , None ), expected = 40.0 )
271+ tester .tgt_power (priority = 0 , power = - 10 , bounds = (None , None ), expected = - 10.0 )
272+ tester .tgt_power (priority = 0 , power = 10 , bounds = (None , None ), expected = 0.0 )
273+ tester .tgt_power (priority = 0 , power = 20 , bounds = (None , None ), expected = 30.0 )
274+ tester .tgt_power (priority = 0 , power = None , bounds = (None , None ), expected = 0.0 )
275+
276+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , 50.0 ), expected = - 10.0 )
277+ tester .bounds (priority = 0 , expected_power = - 10.0 , expected_bounds = (- 10.0 , 50.0 ))
278+
279+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , 20.0 ), expected = None )
280+ tester .bounds (priority = 0 , expected_power = - 10.0 , expected_bounds = (- 10.0 , 0.0 ))
281+
282+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , - 5.0 ), expected = None )
283+ tester .bounds (priority = 0 , expected_power = - 10.0 , expected_bounds = (- 10.0 , - 5.0 ))
284+
285+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 200.0 , - 5.0 ), expected = None )
286+ tester .bounds (priority = 1 , expected_power = - 10.0 , expected_bounds = (- 200.0 , - 5.0 ))
287+ tester .bounds (priority = 0 , expected_power = - 10.0 , expected_bounds = (- 10.0 , - 5.0 ))
288+
289+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 100.0 , - 5.0 ), expected = None )
290+ tester .bounds (priority = 0 , expected_power = - 10.0 , expected_bounds = (- 100.0 , - 5.0 ))
291+
292+ tester .tgt_power (priority = 1 , power = - 40.0 , bounds = (- 100.0 , - 35.0 ), expected = - 40.0 )
293+ tester .bounds (priority = 0 , expected_power = - 40.0 , expected_bounds = (- 100.0 , - 35.0 ))
294+
295+
296+ async def test_matryoshka_with_excl_3 () -> None :
297+ """Tests for the power managing actor.
298+
299+ With inclusion bounds, and exclusion bounds -30.0 to 30.0.
300+ """
301+ batteries = frozenset ({2 , 5 })
302+
303+ system_bounds = battery_pool .PowerMetrics (
304+ timestamp = datetime .now (tz = timezone .utc ),
305+ inclusion_bounds = timeseries .Bounds (
306+ lower = Power .from_watts (- 200.0 ), upper = Power .from_watts (200.0 )
307+ ),
308+ exclusion_bounds = timeseries .Bounds (
309+ lower = Power .from_watts (- 30.0 ), upper = Power .from_watts (30.0 )
310+ ),
311+ )
312+
313+ tester = StatefulTester (batteries , system_bounds )
314+
315+ tester .tgt_power (priority = 2 , power = 25.0 , bounds = (25.0 , 50.0 ), expected = 30.0 )
316+ tester .bounds (priority = 2 , expected_power = 30.0 , expected_bounds = (- 200.0 , 200.0 ))
317+ tester .bounds (priority = 1 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
318+
319+ tester .tgt_power (priority = 1 , power = 20.0 , bounds = (20.0 , 50.0 ), expected = None )
320+ tester .bounds (priority = 1 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
321+
322+ tester .tgt_power (priority = 1 , power = 10.0 , bounds = (5.0 , 10.0 ), expected = None )
323+ tester .bounds (priority = 0 , expected_power = 30.0 , expected_bounds = (30 , 50.0 ))
324+
325+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 10.0 , 50.0 ), expected = None )
326+ tester .bounds (priority = 1 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
327+ tester .bounds (priority = 0 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
328+
329+ tester .tgt_power (priority = 1 , power = 40.0 , bounds = (- 10.0 , 50.0 ), expected = 40.0 )
330+ tester .bounds (priority = 0 , expected_power = 40.0 , expected_bounds = (30.0 , 50.0 ))
331+
332+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 10.0 , 20.0 ), expected = 30.0 )
333+ tester .bounds (priority = 0 , expected_power = 30.0 , expected_bounds = (30.0 , 50.0 ))
334+
335+ tester .tgt_power (priority = 2 , power = - 10.0 , bounds = (- 200.0 , - 5.0 ), expected = - 30.0 )
336+ tester .bounds (priority = 1 , expected_power = - 30.0 , expected_bounds = (- 200.0 , - 30.0 ))
337+ tester .bounds (priority = 0 , expected_power = - 30.0 , expected_bounds = (- 200.0 , - 30.0 ))
338+
339+ tester .tgt_power (priority = 1 , power = - 10.0 , bounds = (- 100.0 , - 5.0 ), expected = None )
340+ tester .bounds (priority = 0 , expected_power = - 30.0 , expected_bounds = (- 100.0 , - 30.0 ))
341+
342+ tester .tgt_power (priority = 1 , power = - 40.0 , bounds = (- 100.0 , - 35.0 ), expected = - 40.0 )
343+ tester .bounds (priority = 0 , expected_power = - 40.0 , expected_bounds = (- 100.0 , - 35.0 ))
0 commit comments