31 lines
1.0 KiB
Python
31 lines
1.0 KiB
Python
from edgemind.plan_cert import PlanCert, verify_plan
|
|
|
|
|
|
def test_verify_plan_pass():
|
|
cert = PlanCert(
|
|
plan_id="p1",
|
|
preconditions=["battery >= 20", "distance_to_goal <= 5"],
|
|
invariants={"safe_speed": "speed <= 1.5"},
|
|
worst_case_energy=5.0,
|
|
)
|
|
|
|
state = {"battery": 50, "distance_to_goal": 3, "speed": 1.0}
|
|
proof = verify_plan(cert, state, energy_budget=10.0)
|
|
assert proof.accepted is True
|
|
assert proof.score > 0.5
|
|
assert proof.reasons == []
|
|
|
|
|
|
def test_verify_plan_fail_precondition_and_energy():
|
|
cert = PlanCert(
|
|
plan_id="p2",
|
|
preconditions=["battery >= 80"],
|
|
invariants={"safe_speed": "speed <= 1.0"},
|
|
worst_case_energy=20.0,
|
|
)
|
|
state = {"battery": 40, "speed": 1.2}
|
|
proof = verify_plan(cert, state, energy_budget=10.0)
|
|
assert proof.accepted is False
|
|
# Expect at least two reasons: precondition failed and energy exceeded
|
|
assert any("precondition" in r or "invariant" in r or "worst_case_energy" in r for r in proof.reasons)
|