Ilyrun-Qhora-II-Gapped-Consecutive-Ones / validation /test_checker_width_alias.py
PureOne's picture
Upload research package with Eve Uploader
19c5f68 verified
Raw History Blame Contribute Delete
1.76 kB
#!/usr/bin/env python3
"""Deterministic regression for the prepared checker's declared-width aliases."""
import importlib.util
from pathlib import Path
import sys
sys.dont_write_bytecode = True
path = Path(__file__).resolve().parents[1] / "source/research/software/checker.py"
spec = importlib.util.spec_from_file_location("release_checker", path)
checker = importlib.util.module_from_spec(spec)
spec.loader.exec_module(checker)
valid_cases = [
({"n": 7, "rows": [[0, 1, 2], [3, 4]], "budgets": [1, 1]}, list(range(7))),
({"n_columns": 7, "rows": [[0, 1, 2], [3, 4]]}, list(range(7))),
({"n": 7, "n_columns": 7, "rows": [[0, 1, 2], [3, 4]]}, list(range(7))),
({"n": 3, "matrix": []}, list(range(3))),
({"n": 3, "rows": []}, list(range(3))),
({"n": 0, "rows": []}, []),
({"rows": [[0, 1], [1, 2]]}, list(range(3))),
({"n": 3, "matrix": [[1, 1, 0], [0, 1, 1]]}, list(range(3))),
]
for data, order in valid_cases:
if not checker.check_permutation(data, order)["valid"]:
raise AssertionError((data, order))
invalid_inputs = [
{"n": 7, "n_columns": 6, "rows": [[0, 1]]},
{"n": 4, "matrix": [[1, 1, 0]]},
{"n": -1, "rows": []},
{"n": True, "rows": []},
]
for data in invalid_inputs:
try:
checker.normalized(data)
except ValueError:
pass
else:
raise AssertionError(("accepted invalid input", data))
if checker.check_permutation({"n": 7, "rows": [[0, 1]]}, list(range(5)))["valid"]:
raise AssertionError("accepted truncated permutation")
if checker.check_permutation({"n": 4, "rows": [[0, 3]], "budget": 1}, list(range(4)))["valid"]:
raise AssertionError("accepted row-budget violation")
print("PASS: 8 valid cases, 4 invalid declarations, 2 invalid witnesses")