30 lines
1.2 KiB
Python
30 lines
1.2 KiB
Python
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src")))
|
|
|
|
from idea15_edgemind_verifiable_onboard.planner import Action, PlanRequest, PlanResult, EdgeMindPlanner
|
|
from idea15_edgemind_verifiable_onboard.contracts import SafetyContract
|
|
|
|
|
|
def test_basic_planning_cheapest_provider(): # simple test ensuring cheapest action per goal is chosen within budget
|
|
a1 = Action(name="move_forward", energy_cost=1.0, provides={"reach_goalA"})
|
|
a2 = Action(name="lift", energy_cost=0.3, provides={"reach_goalA"})
|
|
actions = [a1, a2]
|
|
safety = SafetyContract()
|
|
req = PlanRequest(goals=["reach_goalA"], actions=actions, energy_budget=2.0, safety_contract=safety)
|
|
planner = EdgeMindPlanner()
|
|
res: PlanResult = planner.plan(req)
|
|
assert res.ok
|
|
assert len(res.planned_actions) == 1
|
|
assert res.planned_actions[0].name == "lift"
|
|
assert res.total_energy == 0.3
|
|
|
|
|
|
def test_planning_budget_exceeded():
|
|
a1 = Action(name="move_forward", energy_cost=1.5, provides={"reach_goalA"})
|
|
actions = [a1]
|
|
req = PlanRequest(goals=["reach_goalA"], actions=actions, energy_budget=1.0)
|
|
planner = EdgeMindPlanner()
|
|
res = planner.plan(req)
|
|
assert not res.ok
|