# Eigener lokaler Vergleich, keine API, keine Ausfuehrung von Modellcode.
import json, sys, math
EXPECTED = {'gueltig': ['A', 'B'], 'ungueltig': ['C', 'D', 'E'], 'summe_gueltiger_mengen': 2}
def matches(actual, expected):
    if isinstance(expected, dict):
        return isinstance(actual, dict) and all(k in actual and matches(actual[k], v) for k,v in expected.items())
    if isinstance(expected, list):
        return isinstance(actual, list) and len(actual)==len(expected) and all(matches(a,b) for a,b in zip(actual,expected))
    if expected is None:
        return actual is None
    if isinstance(expected, bool):
        return type(actual) is bool and actual is expected
    if isinstance(expected, (int,float)):
        return type(actual) in (int,float) and math.isfinite(actual) and actual==expected
    return type(actual) is type(expected) and actual==expected
if __name__ == "__main__":
    if len(sys.argv)!=2:
        raise SystemExit("Aufruf: python pruefen.py antwort.json")
    with open(sys.argv[1], encoding="utf-8-sig") as f:
        raw=f.read(1000001)
    if len(raw)>1000000:
        raise SystemExit("Antwort fuer diese kleine Uebung zu gross.")
    try:
        actual=json.loads(raw, parse_constant=lambda s: (_ for _ in ()).throw(ValueError(s)))
    except ValueError:
        raise SystemExit("Kein gueltiges JSON. Speichere nur den JSON-Teil ohne Markdown.")
    good=matches(actual,EXPECTED)
    print("Sollfelder erfuellt." if good else "Abweichung vom Soll. Werte, Typen, Nullangaben und Reihenfolge pruefen.")
    print("Freie Begruendungen, Codequalitaet und Modellleistung werden nicht bewertet.")
    raise SystemExit(0 if good else 1)
