#!/usr/bin/env python3
import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "tools"))
from router_policy import choose_backend

def test_choose_backend_energy_heavy():
    # bytes dominate → prefer dwave profile in our defaults
    metrics = {"cycles": 10_000, "flips": 10_000, "bytes": 20_000_000}
    choice, scores = choose_backend(metrics, prefs={"w_energy":0.95,"w_latency":0.05})
    assert choice in ("dwave","ibm","sa")
    # sanity: energy scores exist
    assert all("energy_pj" in s for s in scores.values())
    print(f"✅ Router energy-heavy test passed: {choice} selected")
    print(f"   Scores: {scores}")

def test_choose_backend_latency_heavy():
    # prefer low overhead → likely SA
    metrics = {"cycles": 1_000, "flips": 1_000, "bytes": 5_000}
    choice, scores = choose_backend(metrics, prefs={"w_energy":0.1,"w_latency":0.9})
    assert choice in ("dwave","ibm","sa")
    assert all("latency_us" in s for s in scores.values())
    print(f"✅ Router latency-heavy test passed: {choice} selected")
    print(f"   Scores: {scores}")

if __name__ == "__main__":
    test_choose_backend_energy_heavy()
    test_choose_backend_latency_heavy()
