"""2kwas: negative control for hardin_check.decide: perturb each claim (last coefficient +1) and check it is rejected."""
import os, sys, json
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from hardin_engine import spec_for
from hardin_check import decide
entries = json.load(open(sys.argv[1]))
tested = rejected = 0
missed = []
for e in entries:
    sp = spec_for(e["id"], e["name"])
    for cl in e["claims"]:
        bad = dict(cl); bad["coef"] = cl["coef"][:-1] + [cl["coef"][-1] + 1]
        d = decide(sp, bad)
        if d["live_states"] == 0:
            continue          # identically zero target: every recurrence holds
        tested += 1
        if not d["holds"]:
            rejected += 1
        else:
            missed.append((e["id"], cl["mode"], cl["idx"]))
print("perturbed claims on non-zero targets: %d, rejected: %d, accepted (should be 0): %s" % (tested, rejected, missed))
