feat(S5): pet rule engine with condition evaluation and cooldown
This commit is contained in:
41
tests/unit/test_pet_rules.py
Normal file
41
tests/unit/test_pet_rules.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import time
|
||||
from vigilar.pets.rules import PetState, evaluate_condition, evaluate_rule
|
||||
|
||||
def test_detected_in_zone_true():
|
||||
state = PetState(pet_id="milo", current_zone="EXTERIOR")
|
||||
assert evaluate_condition({"type": "detected_in_zone", "zone": "EXTERIOR"}, state, time.time()) is True
|
||||
|
||||
def test_detected_in_zone_false():
|
||||
state = PetState(pet_id="milo", current_zone="INTERIOR")
|
||||
assert evaluate_condition({"type": "detected_in_zone", "zone": "EXTERIOR"}, state, time.time()) is False
|
||||
|
||||
def test_not_seen_in_zone_true():
|
||||
now = time.time()
|
||||
state = PetState(pet_id="milo", current_zone="INTERIOR", last_seen_time=now - 3600)
|
||||
assert evaluate_condition({"type": "not_seen_in_zone", "zone": "EXTERIOR", "minutes": 30}, state, now) is True
|
||||
|
||||
def test_not_seen_anywhere():
|
||||
now = time.time()
|
||||
state = PetState(pet_id="milo", last_seen_time=now - 30000)
|
||||
assert evaluate_condition({"type": "not_seen_anywhere", "minutes": 480}, state, now) is True
|
||||
|
||||
def test_detected_without_person():
|
||||
assert evaluate_condition({"type": "detected_without_person"}, PetState(pet_id="snek", person_present=False), time.time()) is True
|
||||
assert evaluate_condition({"type": "detected_without_person"}, PetState(pet_id="snek", person_present=True), time.time()) is False
|
||||
|
||||
def test_in_zone_longer_than():
|
||||
now = time.time()
|
||||
state = PetState(pet_id="milo", current_zone="EXTERIOR", zone_entry_time=now - 3000)
|
||||
assert evaluate_condition({"type": "in_zone_longer_than", "zone": "EXTERIOR", "minutes": 45}, state, now) is True
|
||||
|
||||
def test_evaluate_rule_and_logic():
|
||||
now = time.time()
|
||||
state = PetState(pet_id="milo", current_zone="EXTERIOR", zone_entry_time=now - 3600, person_present=False)
|
||||
rule = {"conditions": [{"type": "detected_in_zone", "zone": "EXTERIOR"}, {"type": "detected_without_person"}]}
|
||||
assert evaluate_rule(rule, state, now) is True
|
||||
|
||||
def test_evaluate_rule_one_fails():
|
||||
now = time.time()
|
||||
state = PetState(pet_id="milo", current_zone="INTERIOR", person_present=False)
|
||||
rule = {"conditions": [{"type": "detected_in_zone", "zone": "EXTERIOR"}, {"type": "detected_without_person"}]}
|
||||
assert evaluate_rule(rule, state, now) is False
|
||||
Reference in New Issue
Block a user