116 lines
1.9 KiB
Python
116 lines
1.9 KiB
Python
from app.auto.config import (
|
|
TemperatureConfig,
|
|
)
|
|
from app.auto.temperature_policy import (
|
|
TemperaturePolicy,
|
|
)
|
|
|
|
|
|
def make_policy() -> TemperaturePolicy:
|
|
|
|
return TemperaturePolicy(
|
|
TemperatureConfig(
|
|
hysteresis=0.5,
|
|
)
|
|
)
|
|
|
|
|
|
def test_heater_off_below_lower_limit():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=19.4,
|
|
target_temp=20.0,
|
|
heater_on=False,
|
|
)
|
|
|
|
assert result is True
|
|
|
|
|
|
def test_heater_off_at_lower_limit():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=19.5,
|
|
target_temp=20.0,
|
|
heater_on=False,
|
|
)
|
|
|
|
assert result is False
|
|
|
|
|
|
def test_heater_off_inside_hysteresis():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=19.8,
|
|
target_temp=20.0,
|
|
heater_on=False,
|
|
)
|
|
|
|
assert result is False
|
|
|
|
|
|
def test_heater_on_below_target():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=19.8,
|
|
target_temp=20.0,
|
|
heater_on=True,
|
|
)
|
|
|
|
assert result is True
|
|
|
|
|
|
def test_heater_on_at_target():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=20.0,
|
|
target_temp=20.0,
|
|
heater_on=True,
|
|
)
|
|
|
|
assert result is False
|
|
|
|
|
|
def test_heater_on_above_target():
|
|
|
|
policy = make_policy()
|
|
|
|
result = policy.heater_required(
|
|
temperature=20.2,
|
|
target_temp=20.0,
|
|
heater_on=True,
|
|
)
|
|
|
|
assert result is False
|
|
|
|
|
|
def main():
|
|
|
|
test_heater_off_below_lower_limit()
|
|
test_heater_off_at_lower_limit()
|
|
test_heater_off_inside_hysteresis()
|
|
|
|
test_heater_on_below_target()
|
|
test_heater_on_at_target()
|
|
test_heater_on_above_target()
|
|
|
|
print()
|
|
print("=" * 70)
|
|
print(
|
|
"ALL AUTO TEMPERATURE POLICY "
|
|
"TESTS PASSED"
|
|
)
|
|
print("=" * 70)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main() |