#!/usr/bin/env python3 """Unit tests for the route 146 job #2953 verification helpers. These test the CHECKERS themselves (parsers, modular derivation, band arithmetic) on fixture values, so a checker bug cannot masquerade as a passing result. The measured logs are exercised by verify_independent.py. Run: python3 -m unittest test_verify -v """ import unittest import verify_independent as vi import verify_sympy as vs class TestModularDerivation(unittest.TestCase): def test_c_p_known_small_primes(self): # hand-computed: 6^-1 mod 5 = 1 -> c=2; 6^-1 mod 7 = 6 -> c=12 mod 7 = 5; # 6^-1 mod 11 = 2 -> c=4 self.assertEqual(vi.c_p(5), 2) self.assertEqual(vi.c_p(7), 5) self.assertEqual(vi.c_p(11), 4) def test_c_p_satisfies_defining_relation(self): for p in vi.PLIST: self.assertEqual((6 * vi.c_p(p)) % p, 2 % p) def test_c_p_table_is_not_constant(self): vals = [vi.c_p(p) for p in vi.PLIST] self.assertGreater(len(set(vals)), 5, "the derived table must actually vary") class TestParsers(unittest.TestCase): LINE = ("SHARED n=17 N=4 mb=160 splitk=3 value=965 best=160 nodes=1789523 " "tuples=135 records=0 leaves=8 wall_ms=14110.5") def test_regexes_extract_the_right_fields(self): import re self.assertEqual(int(re.search(r"nodes=(\d+)", self.LINE).group(1)), 1789523) self.assertEqual(int(re.search(r"best=(\d+)", self.LINE).group(1)), 160) self.assertEqual(int(re.search(r"value=(\d+)", self.LINE).group(1)), 965) def test_value_best_relation(self): self.assertEqual(6 * 160 + 5, 965) class TestSplitTally(unittest.TestCase): def test_all_four_differences_are_386(self): diffs = {n: b - a for n, (a, b, _) in vi.ARM_NODES.items()} self.assertEqual(set(diffs.values()), {386}) def test_negative_fixture_would_be_caught(self): # a deliberately wrong pair must NOT satisfy the constant self.assertNotEqual(1789523 - 1789136, 386) def test_sympy_solver_agrees_with_independent_derivation(self): for p in vs.PLIST: self.assertEqual(vs.solve_c_p(p), vi.c_p(p)) class TestBandArithmetic(unittest.TestCase): def test_within_one_percent_true_case(self): got, ref = 26568575, 26423767 self.assertLess(abs(got - ref) / ref, 0.01) def test_within_one_percent_false_case(self): got, ref = 30000000, 26423767 self.assertGreater(abs(got - ref) / ref, 0.01) def test_factor_band(self): self.assertTrue(3.42 <= 26568575 / 7754620 < 3.43) if __name__ == "__main__": unittest.main(verbosity=2)