31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
import math
|
|
import sys
|
|
import os
|
|
|
|
# Ensure the local src package is importable when tests run from repo root
|
|
src_path = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "src"))
|
|
if src_path not in sys.path:
|
|
sys.path.insert(0, src_path)
|
|
|
|
from ar_grid_tutor_mobile_ar_digital_twin_for.core import TelemetrySample, TwinEngine
|
|
|
|
|
|
def test_reconcile_updates_baseline_and_delta():
|
|
engine = TwinEngine()
|
|
asset_id = "solar-1"
|
|
# initial telemetry comes in; baseline starts empty
|
|
sample1 = TelemetrySample(asset_id=asset_id, timestamp=1.0, metrics={"voltage": 480.0, "temp": 25.0})
|
|
out1 = engine.reconcile(sample1)
|
|
assert out1["asset_id"] == asset_id
|
|
assert out1["version"] == 2 # since initial register creates version 1 and reconcile increments to 2
|
|
assert isinstance(out1["delta"], dict)
|
|
assert out1["delta"]["voltage"] == 480.0 - 0.0
|
|
|
|
# second sample with changed values
|
|
sample2 = TelemetrySample(asset_id=asset_id, timestamp=2.0, metrics={"voltage": 485.0, "temp": 27.0})
|
|
out2 = engine.reconcile(sample2)
|
|
assert out2["asset_id"] == asset_id
|
|
assert out2["version"] == 3
|
|
assert math.isclose(out2["delta"]["voltage"], 5.0, rel_tol=1e-6)
|
|
assert out2["new_baseline"]["voltage"] == 485.0
|