"""CPU contract of the A-versus-window timing harness (no CUDA).""" from pathlib import Path import sys import unittest import numpy as np sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "validation")) import time_window_dfg as w # noqa: E402 class WindowTimingContract(unittest.TestCase): def test_interval_and_variants(self): self.assertEqual(w.INTERVAL, 80) self.assertEqual(w.VARIANTS, ("A", "W", "W1")) def test_components(self): obs = dict(total=dict(impulse=np.array([1., 2.]), angular_impulse=3., mass_into_fluid=4.)) np.testing.assert_array_equal(w.components(obs), [1., 2., 3., 4.]) def test_interval_comparison(self): ref = np.array([[1., -1., 0., 0.]]) scale = np.array([[10., 10., 1., 1.]]) self.assertEqual(w.compare_intervals(ref, scale, ref.copy()), 0.) near = ref + np.array([[5e-9, 0., 0., 0.]]) self.assertLessEqual(w.compare_intervals(ref, scale, near), 1.) far = ref + np.array([[1e-7, 0., 0., 0.]]) self.assertGreater(w.compare_intervals(ref, scale, far), 1.) zero = np.zeros((1, 4)) self.assertGreater(w.compare_intervals(zero, zero, zero + 1e-12), 1.) # floor, no div-by-0 def test_candidate_identity_records_files(self): identity = w.candidate_identity(Path(__file__).resolve().parents[2]) self.assertIn("checkout_revision", identity) self.assertEqual(set(identity["sha256"]), set(w.CANDIDATE_FILES)) if __name__ == "__main__": unittest.main()