|
11 | 11 |
|
12 | 12 |
|
13 | 13 | 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.""" |
18 | 15 | 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 |
19 | 21 |
|
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 |
25 | 22 |
|
| 23 | +def test_bounds_contains_no_lower() -> None: |
| 24 | + """Tests without lower bound.""" |
26 | 25 | 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 | + |
30 | 30 |
|
| 31 | +def test_bounds_contains_no_upper() -> None: |
| 32 | + """Tests without upper bound.""" |
31 | 33 | 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 |
35 | 37 |
|
36 | 38 |
|
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 | + |
40 | 44 |
|
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.""" |
45 | 51 | system_bounds = SystemBounds( |
46 | 52 | timestamp=datetime.now(), |
47 | | - inclusion_bounds=inclusion_bounds, |
48 | | - exclusion_bounds=exclusion_bounds, |
| 53 | + inclusion_bounds=INCLUSION_BOUND, |
| 54 | + exclusion_bounds=EXCLUSION_BOUND, |
49 | 55 | ) |
50 | 56 |
|
51 | 57 | 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 | + |
56 | 61 |
|
| 62 | +def test_system_bounds_contains_no_exclusion() -> None: |
| 63 | + """Tests with no exclusion bounds.""" |
57 | 64 | system_bounds_no_exclusion = SystemBounds( |
58 | 65 | timestamp=datetime.now(), |
59 | | - inclusion_bounds=inclusion_bounds, |
| 66 | + inclusion_bounds=INCLUSION_BOUND, |
60 | 67 | exclusion_bounds=None, |
61 | 68 | ) |
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 |
66 | 71 |
|
| 72 | + |
| 73 | +def test_system_bounds_contains_no_inclusion() -> None: |
| 74 | + """Tests with no inclusion bounds.""" |
67 | 75 | system_bounds_no_inclusion = SystemBounds( |
68 | 76 | timestamp=datetime.now(), |
69 | 77 | 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, |
71 | 90 | ) |
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