#!/usr/bin/env python3 """unittest suite for the exact arithmetic of finding #2617 (job #3849). The four-runs 60+126+60 belong to the fold of T29 by p = 31, and 82.67 is the refuted old expression 3p - p/(L-1) at p = 31, not a rival tight bound. Run: .venv/Scripts/python.exe -m unittest outputs.job3849.test_verify_finding2617 """ import os import sys import unittest from sympy import Integer, Rational, simplify, symbols sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) p, s, L = symbols("p s L", positive=True) def small_class(pp): return 2 * pp - 2 if pp % 6 == 1 else 2 * pp + 2 def large_class(pp): return 4 * pp + 2 if pp % 6 == 1 else 4 * pp - 2 def qualifying_set(pp): six = 6 * pp aP = 2 while aP % 6 != 0: aP += pp return sorted([six, aP, six - aP]) class TestFinding2617(unittest.TestCase): def test_fold_prime_classes(self): # p = 31 = 1 (mod 6) self.assertEqual(small_class(31), 60) self.assertEqual(large_class(31), 126) self.assertEqual(small_class(31) + large_class(31), 6 * 31) def test_run_word_mean_is_82(self): self.assertEqual(sum([60, 126, 60]), 246) self.assertEqual(Rational(246, 3), 82) def test_corrected_bound_is_exactly_tight(self): got = 3 * 31 - Rational(3 * 31 - 60, 4 - 1) self.assertEqual(got, 82) def test_corrected_bound_identity(self): diff = simplify((3 * p * (L - 2) + s) / (L - 1) - (3 * p - (3 * p - s) / (L - 1))) self.assertEqual(diff, 0) def test_old_bound_is_82_67_and_fails(self): old = 3 * 31 - Rational(31, 4 - 1) self.assertEqual(old, Rational(248, 3)) self.assertEqual(f"{float(old):.2f}", "82.67") self.assertGreater(old, 82) # the observed mean is 82 def test_p29_cannot_carry_the_word(self): self.assertEqual(small_class(29), 60) # twin pair shares 2(p+1) self.assertEqual(large_class(29), 114) self.assertEqual(126 % 29, 10) self.assertNotIn(126 % 29, (0, 2, 29 - 2)) self.assertNotIn(126, qualifying_set(29)) def test_qualifying_sets(self): self.assertEqual(qualifying_set(31), [60, 126, 186]) self.assertEqual(qualifying_set(29), [60, 114, 174]) # the label "p = 29" is also contradicted by the printed 82.67: self.assertNotEqual(3 * 29 - Rational(29, 3), Rational(248, 3)) @unittest.skipUnless( os.path.exists(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname( os.path.abspath(__file__)))), "outputs", "job3849", "a3-08-adjacent-pairs.js")), "local staged artefacts absent") def test_served_and_revised_text(self): import hashlib root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) served = os.path.join(root, "outputs", "job3849", "served", "a3-08-adjacent-pairs.js") rev = os.path.join(root, "outputs", "job3849", "a3-08-adjacent-pairs.js") with open(served, encoding="utf-8") as fa, open(rev, encoding="utf-8") as fb: a, b = fa.read(), fb.read() self.assertIn("have mean 82 against 82.67 for L = 4, p = 29.", a) self.assertNotIn("have mean 82 against 82.67 for L = 4, p = 29.", b) self.assertIn("have mean 82 = 3p - (3p - s)/(L-1) =", b) self.assertIn("for L = 4, p = 31, s = 60 (the old 3p - p/(L-1) = 82.67 fails).", b) self.assertEqual(hashlib.sha256(a.encode()).hexdigest(), "eabc5c89a8ea2c7fcee018d41d126c6e47fbcfae9cde8c696923088db1d3477b") self.assertEqual(hashlib.sha256(b.encode()).hexdigest(), "dbd6315b6e48ee83b0fcf9346456f70bdbb107211a4734e74b880e817b96b07e") # the edit is comment-only import difflib for ln in difflib.unified_diff(a.splitlines(), b.splitlines(), lineterm="", n=0): if ln[:1] in "+-" and not ln.startswith(("+++", "---")): self.assertTrue(ln[1:].lstrip().startswith("//"), f"non-comment change: {ln}") if __name__ == "__main__": unittest.main(verbosity=2)