Skip to content

Commit b6a669a

Browse files
Add consumption and production formula tests
Signed-off-by: Matthias Wende <[email protected]>
1 parent 922262a commit b6a669a

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

tests/timeseries/test_formula_engine.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,19 @@ async def run_test( # pylint: disable=too-many-locals
318318
num_items: int,
319319
make_builder: (
320320
Callable[
321+
[
322+
FormulaEngine[Quantity],
323+
],
324+
HigherOrderFormulaBuilder[Quantity],
325+
]
326+
| Callable[
327+
[
328+
FormulaEngine[Quantity],
329+
FormulaEngine[Quantity],
330+
],
331+
HigherOrderFormulaBuilder[Quantity],
332+
]
333+
| Callable[
321334
[
322335
FormulaEngine[Quantity],
323336
FormulaEngine[Quantity],
@@ -586,6 +599,95 @@ async def test_compound(self) -> None:
586599
],
587600
)
588601

602+
async def test_consumption(self) -> None:
603+
"""Test the consumption operator."""
604+
await self.run_test(
605+
1,
606+
lambda c1: c1.consumption(),
607+
[
608+
([10.0], 10.0),
609+
([-10.0], 0.0),
610+
],
611+
)
612+
613+
async def test_production(self) -> None:
614+
"""Test the production operator."""
615+
await self.run_test(
616+
1,
617+
lambda c1: c1.production(),
618+
[
619+
([10.0], 0.0),
620+
([-10.0], 10.0),
621+
],
622+
)
623+
624+
async def test_consumption_production(self) -> None:
625+
"""Test the consumption and production operator combined."""
626+
await self.run_test(
627+
2,
628+
lambda c1, c2: c1.consumption() + c2.production(),
629+
[
630+
([10.0, 12.0], 10.0),
631+
([-12.0, -10.0], 10.0),
632+
],
633+
)
634+
await self.run_test(
635+
2,
636+
lambda c1, c2: c1.consumption() + c2.consumption(),
637+
[
638+
([10.0, -12.0], 10.0),
639+
([-10.0, 12.0], 12.0),
640+
],
641+
)
642+
await self.run_test(
643+
2,
644+
lambda c1, c2: c1.production() + c2.production(),
645+
[
646+
([10.0, -12.0], 12.0),
647+
([-10.0, 12.0], 10.0),
648+
],
649+
)
650+
await self.run_test(
651+
2,
652+
lambda c1, c2: c1.min(c2).consumption(),
653+
[
654+
([10.0, -12.0], 0.0),
655+
([10.0, 12.0], 10.0),
656+
],
657+
)
658+
await self.run_test(
659+
2,
660+
lambda c1, c2: c1.max(c2).consumption(),
661+
[
662+
([10.0, -12.0], 10.0),
663+
([-10.0, -12.0], 0.0),
664+
],
665+
)
666+
await self.run_test(
667+
2,
668+
lambda c1, c2: c1.min(c2).production(),
669+
[
670+
([10.0, -12.0], 12.0),
671+
([10.0, 12.0], 0.0),
672+
],
673+
)
674+
await self.run_test(
675+
2,
676+
lambda c1, c2: c1.max(c2).production(),
677+
[
678+
([10.0, -12.0], 0.0),
679+
([-10.0, -12.0], 10.0),
680+
],
681+
)
682+
await self.run_test(
683+
2,
684+
lambda c1, c2: c1.production() + c2,
685+
[
686+
([10.0, -12.0], -12.0),
687+
([-10.0, -12.0], -2.0),
688+
],
689+
)
690+
589691
async def test_nones_are_zeros(self) -> None:
590692
"""Test that `None`s are treated as zeros when configured."""
591693
await self.run_test(

0 commit comments

Comments
 (0)