Skip to content

Commit 33178e1

Browse files
committed
Unittest the shifting matryoshka algorithm
Signed-off-by: Sahas Subramanian <[email protected]>
1 parent a0137e0 commit 33178e1

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

tests/actor/_power_managing/test_shifting_matryoshka.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,65 @@ def ensure_overlapping_bucket_request_fails() -> None:
543543
expected=20.0,
544544
batteries=overlapping_batteries,
545545
)
546+
547+
548+
async def test_matryoshka_shifting_limiting() -> None:
549+
"""Tests for the power managing actor.
550+
551+
With the following scenario:
552+
553+
| actor | available | req | req bounds | s/l | unshifted | shifted |
554+
| priority | bounds | power | | | power | power |
555+
|----------|-------------|-------|------------|--------|-----------|---------|
556+
| 7 | -100 to 100 | 10 | None | shifts | 10 | 10 |
557+
|----------|-------------|-------|------------|--------|-----------|---------|
558+
| 6 | -110 to 90 | 10 | -110 to 80 | limits | | |
559+
| 5 | -110 to 80 | 80 | -100 to 80 | limits | | |
560+
| 4 | -100 to 80 | -120 | None | shifts | -100 | -90 |
561+
|----------|-------------|-------|------------|--------|-----------|---------|
562+
| 3 | 0 to 180 | 60 | None | shifts | 60 | -30 |
563+
|----------|-------------|-------|------------|--------|-----------|---------|
564+
| 2 | -60 to 120 | 20 | -40 to 30 | limits | | |
565+
| 1 | -40 to 30 | 12 | None | shifts | 12 | -18 |
566+
|----------|-------------|-------|------------|--------|-----------|---------|
567+
| 0 | -52 to 18 | -10 | -40 to -10 | limits | -10 | -28 |
568+
|----------|-------------|-------|------------|--------|-----------|---------|
569+
| | | | | target | | |
570+
| | | | | power | -28 | |
571+
"""
572+
batteries = frozenset({2, 5})
573+
574+
system_bounds = _base_types.SystemBounds(
575+
timestamp=datetime.now(tz=timezone.utc),
576+
inclusion_bounds=timeseries.Bounds(
577+
lower=Power.from_watts(-100.0), upper=Power.from_watts(100.0)
578+
),
579+
exclusion_bounds=timeseries.Bounds(
580+
lower=Power.from_watts(-0.0), upper=Power.from_watts(0.0)
581+
),
582+
)
583+
584+
tester = StatefulTester(batteries, system_bounds)
585+
tester.tgt_power(priority=7, power=10.0, bounds=(None, None), expected=10.0)
586+
tester.bounds(priority=7, expected_power=10.0, expected_bounds=(-100.0, 100.0))
587+
tester.bounds(priority=6, expected_power=10.0, expected_bounds=(-110.0, 90.0))
588+
589+
tester.tgt_power(priority=6, power=10.0, bounds=(-110.0, 80.0), expected=20.0)
590+
tester.bounds(priority=5, expected_power=20.0, expected_bounds=(-110.0, 80.0))
591+
592+
tester.tgt_power(priority=5, power=80.0, bounds=(-100.0, 80.0), expected=90.0)
593+
tester.bounds(priority=4, expected_power=90.0, expected_bounds=(-100.0, 80.0))
594+
595+
tester.tgt_power(priority=4, power=-120.0, bounds=(None, None), expected=-90.0)
596+
tester.bounds(priority=3, expected_power=-90.0, expected_bounds=(0.0, 180.0))
597+
598+
tester.tgt_power(priority=3, power=60.0, bounds=(None, None), expected=-30.0)
599+
tester.bounds(priority=2, expected_power=-30.0, expected_bounds=(-60.0, 120.0))
600+
601+
tester.tgt_power(priority=2, power=20.0, bounds=(-40.0, 30.0), expected=-10.0)
602+
tester.bounds(priority=1, expected_power=-10.0, expected_bounds=(-40.0, 30.0))
603+
604+
tester.tgt_power(priority=1, power=12.0, bounds=(None, None), expected=-18.0)
605+
tester.bounds(priority=0, expected_power=-18.0, expected_bounds=(-52.0, 18.0))
606+
607+
tester.tgt_power(priority=0, power=-10.0, bounds=(-40.0, -10.0), expected=-28.0)

0 commit comments

Comments
 (0)