"""Original AI Essay practice: requirements before accepting a code change.

https://ai-essay.com/tools/github-copilot#specification-boundary-practice
Run with Python 3 and its standard library: python3 <this-file.py>
The deliberately flawed candidate is constructed teaching code, not a response
obtained from Copilot or another AI product. This is not a security validator.

Contract: input is a Python string. Accept exactly two ASCII uppercase letters,
a literal hyphen, then three ASCII digits, matching the entire string. Reject
whitespace; do not trim or normalize the input. No real course records are used.
Try predicting the cases before inspecting the functions and expected results.
The file performs no network, account, installation, or file-writing operation.
"""
import re
import sys

CASES = [
    ("valid-middle", "AB-123", True),
    ("valid-zero", "XY-000", True),
    ("valid-nine", "ZQ-999", True),
    ("lowercase", "ab-123", False),
    ("one-letter", "A-123", False),
    ("three-letters", "ABC-123", False),
    ("missing-hyphen", "AB123", False),
    ("two-digits", "AB-12", False),
    ("four-digits", "AB-1234", False),
    ("arabic-indic-digits", "AB-\u0661\u0662\u0663", False),
    ("fullwidth-digits", "AB-\uff11\uff12\uff13", False),
    ("terminal-newline", "AB-123\n", False),
    ("leading-space", " AB-123", False),
    ("trailing-space", "AB-123 ", False),
    ("empty", "", False),
]


def constructed_candidate(value):
    return bool(re.match(r"^[A-Z]{2}-\d{3}$", value))


def repaired_candidate(value):
    return bool(re.fullmatch(r"[A-Z]{2}-[0-9]{3}", value))


def main():
    mismatches = []
    for label, value, expected in CASES:
        actual = constructed_candidate(value)
        if actual != expected:
            mismatches.append(label)
        repaired = repaired_candidate(value)
        if repaired != expected:
            raise AssertionError((label, repr(value), expected, repaired))
    expected_mismatches = ["arabic-indic-digits", "fullwidth-digits", "terminal-newline"]
    if mismatches != expected_mismatches:
        raise AssertionError(("Unexpected constructed-candidate record", mismatches))
    print("Python " + sys.version.split()[0])
    print("Constructed candidate: " + str(len(mismatches)) + " mismatches out of " + str(len(CASES)))
    print("Counterexamples: " + ", ".join(mismatches))
    print("Repaired candidate: " + str(len(CASES)) + "/" + str(len(CASES)) + " stated cases agree with the contract")
    print("This finite check is not proof of every program property or a Copilot product test.")


if __name__ == "__main__":
    main()
