holy agent
This commit is contained in:
BIN
tests/__pycache__/test_adapter.cpython-312.pyc
Normal file
BIN
tests/__pycache__/test_adapter.cpython-312.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_api.cpython-312.pyc
Normal file
BIN
tests/__pycache__/test_api.cpython-312.pyc
Normal file
Binary file not shown.
BIN
tests/__pycache__/test_enrichment.cpython-312.pyc
Normal file
BIN
tests/__pycache__/test_enrichment.cpython-312.pyc
Normal file
Binary file not shown.
32
tests/test_adapter.py
Normal file
32
tests/test_adapter.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import unittest
|
||||
|
||||
from hpcsim.adapter import normalize_telemetry
|
||||
|
||||
|
||||
class TestAdapter(unittest.TestCase):
|
||||
def test_alias_mapping_and_clamping(self):
|
||||
raw = {
|
||||
"LapNumber": "12",
|
||||
"Speed": "280.5",
|
||||
"Throttle": 1.2, # will clamp
|
||||
"Brakes": -0.1, # will clamp
|
||||
"TyreCompound": "Soft",
|
||||
"FuelRel": 1.5, # will clamp
|
||||
"ERS": 0.45,
|
||||
"TrackTemp": "41",
|
||||
"RainProb": 0.3,
|
||||
}
|
||||
norm = normalize_telemetry(raw)
|
||||
self.assertEqual(norm["lap"], 12)
|
||||
self.assertAlmostEqual(norm["speed"], 280.5, places=2)
|
||||
self.assertEqual(norm["throttle"], 1.0)
|
||||
self.assertEqual(norm["brake"], 0.0)
|
||||
self.assertEqual(norm["tire_compound"], "soft")
|
||||
self.assertEqual(norm["fuel_level"], 1.0)
|
||||
self.assertIn("ers", norm)
|
||||
self.assertIn("track_temp", norm)
|
||||
self.assertIn("rain_probability", norm)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
47
tests/test_api.py
Normal file
47
tests/test_api.py
Normal file
@@ -0,0 +1,47 @@
|
||||
import unittest
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from hpcsim.api import app
|
||||
|
||||
|
||||
class TestAPI(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.client = TestClient(app)
|
||||
|
||||
def test_ingest_and_list(self):
|
||||
payload = {
|
||||
"lap": 1,
|
||||
"speed": 250,
|
||||
"throttle": 0.8,
|
||||
"brake": 0.1,
|
||||
"tire_compound": "medium",
|
||||
"fuel_level": 0.6,
|
||||
}
|
||||
r = self.client.post("/ingest/telemetry", json=payload)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
enriched = r.json()
|
||||
self.assertIn("aero_efficiency", enriched)
|
||||
|
||||
list_r = self.client.get("/enriched", params={"limit": 5})
|
||||
self.assertEqual(list_r.status_code, 200)
|
||||
data = list_r.json()
|
||||
self.assertTrue(isinstance(data, list) and len(data) >= 1)
|
||||
|
||||
def test_post_enriched(self):
|
||||
enriched = {
|
||||
"lap": 99,
|
||||
"aero_efficiency": 0.8,
|
||||
"tire_degradation_index": 0.5,
|
||||
"ers_charge": 0.6,
|
||||
"fuel_optimization_score": 0.9,
|
||||
"driver_consistency": 0.95,
|
||||
"weather_impact": "low",
|
||||
}
|
||||
r = self.client.post("/enriched", json=enriched)
|
||||
self.assertEqual(r.status_code, 200)
|
||||
self.assertEqual(r.json()["lap"], 99)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
46
tests/test_enrichment.py
Normal file
46
tests/test_enrichment.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import unittest
|
||||
|
||||
from hpcsim.enrichment import Enricher
|
||||
|
||||
|
||||
class TestEnrichment(unittest.TestCase):
|
||||
def test_basic_ranges(self):
|
||||
e = Enricher()
|
||||
sample = {
|
||||
"lap": 1,
|
||||
"speed": 250,
|
||||
"throttle": 0.8,
|
||||
"brake": 0.1,
|
||||
"tire_compound": "medium",
|
||||
"fuel_level": 0.6,
|
||||
"ers": 0.5,
|
||||
"track_temp": 35,
|
||||
"rain_probability": 0.1,
|
||||
}
|
||||
out = e.enrich(sample)
|
||||
self.assertIn("aero_efficiency", out)
|
||||
self.assertTrue(0.0 <= out["aero_efficiency"] <= 1.0)
|
||||
self.assertTrue(0.0 <= out["tire_degradation_index"] <= 1.0)
|
||||
self.assertTrue(0.0 <= out["ers_charge"] <= 1.0)
|
||||
self.assertTrue(0.0 <= out["fuel_optimization_score"] <= 1.0)
|
||||
self.assertTrue(0.0 <= out["driver_consistency"] <= 1.0)
|
||||
self.assertIn(out["weather_impact"], {"low", "medium", "high"})
|
||||
|
||||
def test_stateful_wear_increases(self):
|
||||
e = Enricher()
|
||||
prev = 0.0
|
||||
for lap in range(1, 6):
|
||||
out = e.enrich({
|
||||
"lap": lap,
|
||||
"speed": 260,
|
||||
"throttle": 0.9,
|
||||
"brake": 0.05,
|
||||
"tire_compound": "soft",
|
||||
"fuel_level": 0.7,
|
||||
})
|
||||
self.assertGreaterEqual(out["tire_degradation_index"], prev)
|
||||
prev = out["tire_degradation_index"]
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user