Skip to content

Commit 4863fed

Browse files
jack-herrmannllucax
authored andcommitted
Add further tests and split existing tests
Signed-off-by: Jack <[email protected]>
1 parent b1491be commit 4863fed

File tree

2 files changed

+57
-37
lines changed

2 files changed

+57
-37
lines changed

RELEASE_NOTES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
<!-- Here goes the main new features and examples or instructions on how to use them -->
1717

18+
- Classes Bounds and SystemBounds now work with the `in` operator
19+
1820
## Bug Fixes
1921

2022
- Fixed a typing issue that occurs in some cases when composing formulas with constants.

tests/timeseries/test_base_types.py

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,64 +11,82 @@
1111

1212

1313
def test_bounds_contains() -> None:
14-
"""Test the `__contains__` method of the `Bounds` class.
15-
16-
This method checks if a value is within the defined bounds.
17-
"""
14+
"""Tests with complete bounds."""
1815
bounds = Bounds(lower=Power.from_watts(10), upper=Power.from_watts(100))
16+
assert Power.from_watts(50) in bounds # within
17+
assert Power.from_watts(10) in bounds # at lower
18+
assert Power.from_watts(100) in bounds # at upper
19+
assert Power.from_watts(9) not in bounds # below lower
20+
assert Power.from_watts(101) not in bounds # above upper
1921

20-
assert Power.from_watts(50) in bounds # within bounds
21-
assert Power.from_watts(10) in bounds # at lower bound
22-
assert Power.from_watts(100) in bounds # at upper bound
23-
assert Power.from_watts(9) not in bounds # below lower bound
24-
assert Power.from_watts(101) not in bounds # above upper bound
2522

23+
def test_bounds_contains_no_lower() -> None:
24+
"""Tests without lower bound."""
2625
bounds_no_lower = Bounds(lower=None, upper=Power.from_watts(100))
27-
assert Power.from_watts(50) in bounds_no_lower # within upper bound
28-
assert Power.from_watts(100) in bounds_no_lower # at upper bound
29-
assert Power.from_watts(101) not in bounds_no_lower # above upper bound
26+
assert Power.from_watts(50) in bounds_no_lower # within upper
27+
assert Power.from_watts(100) in bounds_no_lower # at upper
28+
assert Power.from_watts(101) not in bounds_no_lower # above upper
29+
3030

31+
def test_bounds_contains_no_upper() -> None:
32+
"""Tests without upper bound."""
3133
bounds_no_upper = Bounds(lower=Power.from_watts(10), upper=None)
32-
assert Power.from_watts(50) in bounds_no_upper # within lower bound
33-
assert Power.from_watts(10) in bounds_no_upper # at lower bound
34-
assert Power.from_watts(9) not in bounds_no_upper # below lower bound
34+
assert Power.from_watts(50) in bounds_no_upper # within lower
35+
assert Power.from_watts(10) in bounds_no_upper # at lower
36+
assert Power.from_watts(9) not in bounds_no_upper # below lower
3537

3638

37-
def test_system_bounds_contains() -> None:
38-
"""
39-
Test the `__contains__` method of the `SystemBounds` class.
39+
def test_bounds_contains_no_bounds() -> None:
40+
"""Tests with no bounds."""
41+
bounds_no_bounds: Bounds[Power | None] = Bounds(lower=None, upper=None)
42+
assert Power.from_watts(50) in bounds_no_bounds # any value within bounds
43+
4044

41-
Checks if value is within inclusion bounds and not exclusion bounds.
42-
"""
43-
inclusion_bounds = Bounds(lower=Power.from_watts(10), upper=Power.from_watts(100))
44-
exclusion_bounds = Bounds(lower=Power.from_watts(40), upper=Power.from_watts(50))
45+
INCLUSION_BOUND = Bounds(lower=Power.from_watts(10), upper=Power.from_watts(100))
46+
EXCLUSION_BOUND = Bounds(lower=Power.from_watts(40), upper=Power.from_watts(50))
47+
48+
49+
def test_system_bounds_contains() -> None:
50+
"""Tests with complete system bounds."""
4551
system_bounds = SystemBounds(
4652
timestamp=datetime.now(),
47-
inclusion_bounds=inclusion_bounds,
48-
exclusion_bounds=exclusion_bounds,
53+
inclusion_bounds=INCLUSION_BOUND,
54+
exclusion_bounds=EXCLUSION_BOUND,
4955
)
5056

5157
assert Power.from_watts(30) in system_bounds # within inclusion, not in exclusion
52-
assert (
53-
Power.from_watts(45) not in system_bounds
54-
) # within inclusion, also in exclusion
55-
assert Power.from_watts(110) not in system_bounds # outside inclusion bounds
58+
assert Power.from_watts(45) not in system_bounds # within inclusion and exclusion
59+
assert Power.from_watts(110) not in system_bounds # outside inclusion
60+
5661

62+
def test_system_bounds_contains_no_exclusion() -> None:
63+
"""Tests with no exclusion bounds."""
5764
system_bounds_no_exclusion = SystemBounds(
5865
timestamp=datetime.now(),
59-
inclusion_bounds=inclusion_bounds,
66+
inclusion_bounds=INCLUSION_BOUND,
6067
exclusion_bounds=None,
6168
)
62-
assert Power.from_watts(30) in system_bounds_no_exclusion # within inclusion bounds
63-
assert (
64-
Power.from_watts(110) not in system_bounds_no_exclusion
65-
) # outside inclusion bounds
69+
assert Power.from_watts(30) in system_bounds_no_exclusion # within inclusion
70+
assert Power.from_watts(110) not in system_bounds_no_exclusion # outside inclusion
6671

72+
73+
def test_system_bounds_contains_no_inclusion() -> None:
74+
"""Tests with no inclusion bounds."""
6775
system_bounds_no_inclusion = SystemBounds(
6876
timestamp=datetime.now(),
6977
inclusion_bounds=None,
70-
exclusion_bounds=exclusion_bounds,
78+
exclusion_bounds=EXCLUSION_BOUND,
79+
)
80+
assert Power.from_watts(30) not in system_bounds_no_inclusion # outside exclusion
81+
assert Power.from_watts(45) not in system_bounds_no_inclusion # within exclusion
82+
83+
84+
def test_system_bounds_contains_no_bounds() -> None:
85+
"""Tests with no bounds."""
86+
system_bounds_no_bounds = SystemBounds(
87+
timestamp=datetime.now(),
88+
inclusion_bounds=None,
89+
exclusion_bounds=None,
7190
)
72-
assert (
73-
Power.from_watts(30) not in system_bounds_no_inclusion
74-
) # not in inclusion bounds
91+
assert Power.from_watts(30) not in system_bounds_no_bounds # any value outside
92+
assert Power.from_watts(110) not in system_bounds_no_bounds # any value outside

0 commit comments

Comments
 (0)