38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
import pytest
|
|
|
|
from energiamesh.core import LocalProblem, SharedVariables, PlanDelta, DualVariables, AuditLog, GraphOfContracts
|
|
|
|
|
|
def test_local_problem_basic():
|
|
lp = LocalProblem(site_id="SiteA", objective="minimize_cost")
|
|
assert lp.site_id == "SiteA"
|
|
assert lp.status == "pending"
|
|
lp.start()
|
|
assert lp.status == "running"
|
|
lp.complete()
|
|
assert lp.status == "completed"
|
|
|
|
|
|
def test_shared_variables_update():
|
|
sv = SharedVariables()
|
|
sv.update("forecast", {"temp": 22})
|
|
assert sv.version == 1
|
|
assert sv.signals["forecast"] == {"temp": 22}
|
|
|
|
|
|
def test_plan_delta_and_dual_variables():
|
|
pd = PlanDelta(delta_id="d1", updates={"x": 1})
|
|
dv = DualVariables(multipliers={"p1": 0.5}, primal={"y": 2})
|
|
assert pd.delta_id == "d1"
|
|
assert dv.multipliers["p1"] == 0.5
|
|
|
|
|
|
def test_audit_log_and_contract_registry():
|
|
al = AuditLog()
|
|
al.add_entry({"event": "start"})
|
|
assert len(al.entries) == 1
|
|
|
|
g = GraphOfContracts()
|
|
g.register_contract("c1", {"name": "TestContract"})
|
|
assert g.get_contract("c1")["name"] == "TestContract"
|