39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
import json
|
|
from datetime import datetime
|
|
|
|
from idea151_aidmesh_federated_privacy.models import LocalProblem, SharedSignals, PlanDelta, DualVariables, AuditLog, PolicyBlock
|
|
|
|
|
|
def test_local_problem_dataclass_roundtrip():
|
|
lp = LocalProblem(
|
|
id="lp-001",
|
|
domain="water_dist",
|
|
assets={"water_kL": 1000},
|
|
objectives=["maximize_delivery"],
|
|
constraints={"max_distance": 50},
|
|
)
|
|
d = lp.to_dict()
|
|
assert d["id"] == "lp-001"
|
|
assert d["domain"] == "water_dist"
|
|
|
|
|
|
def test_shared_signals_roundtrip():
|
|
ss = SharedSignals(forecast={"demand": 100}, capacity_proxies={"truck": 5}, privacy_budget=0.5, version=2)
|
|
assert ss.to_dict()["capacity_proxies"]["truck"] == 5
|
|
|
|
|
|
def test_plan_delta_signature_and_dict():
|
|
pd = PlanDelta(delta={"alloc": {"lp-001": 30}}, timestamp=datetime(2020, 1, 1), author="org-a", contract_id="c-1", signature="sig")
|
|
d = pd.to_dict()
|
|
assert d["contract_id"] == "c-1"
|
|
assert d["author"] == "org-a"
|
|
|
|
|
|
def test_dual_audit_and_policy_blocks():
|
|
dv = DualVariables(multipliers={"x": 1.0})
|
|
ab = AuditLog(entry="test", signer="org-a", timestamp=datetime(2020, 1, 2), contract_id="c-1", version=1)
|
|
pb = PolicyBlock(safety_exposure=0.1, data_exposure_limit=0.2)
|
|
assert dv.multipliers["x"] == 1.0
|
|
assert ab.signer == "org-a"
|
|
assert pb.safety_exposure == 0.1
|