#!/usr/bin/env python3 """Verify the supplied enumeration and exact examples from any working directory.""" from __future__ import annotations import argparse import json from pathlib import Path import subprocess import sys ROOT = Path(__file__).resolve().parents[1] CODE = ROOT / 'code' DATA = ROOT / 'data' def run_json(script: str, arguments: list[str]) -> dict | list: completed = subprocess.run( [sys.executable, str(CODE / script), *arguments], check=True, text=True, stdout=subprocess.PIPE, ) return json.loads(completed.stdout) def main() -> None: if not __debug__: raise RuntimeError('Run without -O: assertion checks are required') parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('--output', type=Path, help='write a complete verification report') args = parser.parse_args() streams = sorted((DATA / 'enumeration').glob('*.jsonl')) if len(streams) != 10: raise RuntimeError('Expected ten terminal-matrix files') integers = run_json('check_certificates.py', [str(x) for x in streams]) coverage = run_json('check_coverage.py', [str(DATA / 'enumeration')]) examples = run_json('examples.py', []) low_dimensions = run_json('check_low_dimensions.py', []) total = sum(s['certificates'] for s in integers['streams']) roots = sum(p['root_cases'] for p in coverage['parameters']) assert total == 113256 and roots == 9719 result = {'integer_checks': integers, 'coverage_checks': coverage, 'example_checks': examples, 'low_dimension_checks': low_dimensions} if args.output: args.output.write_text(json.dumps(result, indent=2) + '\n') print(f'All {total:,} integer identities verified.') print(f'All {roots:,} initial cases covered exactly once.') print('Exact examples and matching numbers verified.') print('All small remainders for at most five patterns verified.') if __name__ == '__main__': main()