42 lines
1.2 KiB
Python
42 lines
1.2 KiB
Python
import unittest
|
|
import sys
|
|
import os
|
|
|
|
# Ensure the local src layout is importable in test runs
|
|
SRC_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "src")
|
|
if os.path.isdir(SRC_DIR) and SRC_DIR not in sys.path:
|
|
sys.path.insert(0, SRC_DIR)
|
|
|
|
from cosmosmesh_privacy_preserving_federated.catopt_bridge import (
|
|
LocalProblem,
|
|
SharedVariables,
|
|
PlanDelta,
|
|
to_catopt,
|
|
from_catopt,
|
|
)
|
|
|
|
|
|
class TestCatOptBridge(unittest.TestCase):
|
|
def test_roundtrip(self):
|
|
lp = LocalProblem(
|
|
id="lp1",
|
|
domain="space",
|
|
assets=["rover1"],
|
|
objective="minimize_energy",
|
|
constraints={"max_time": 1000},
|
|
)
|
|
sv = SharedVariables(forecasts={"energy": 42}, priors={"energy": 40}, version=1)
|
|
delta = PlanDelta(delta={"a": 1}, timestamp="2026-01-01T00:00:00Z", author="tester", contract_id="c1", signature="sig")
|
|
|
|
catopt = to_catopt(lp, sv, delta)
|
|
self.assertIn("Objects", catopt)
|
|
self.assertIn("PlanDelta", catopt)
|
|
|
|
recon = from_catopt(catopt)
|
|
self.assertIn("LocalProblem", recon)
|
|
self.assertIn("PlanDelta", recon)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|