LABELS = {"A": 0, "B": 1, "C": 0, "D": 1}


def evaluate(split):
    # Group IDs are features of this deliberately memorizing baseline.
    if split == "row":
        train, test = list(LABELS), list(LABELS)
    else:
        train, test = ["A", "B"], ["C", "D"]
    memory = {group: LABELS[group] for group in train}
    predictions = [memory.get(group, 0) for group in test]
    accuracy = sum(p == LABELS[g] for p, g in zip(predictions, test)) / len(test)
    return {"train": train, "test": test,
            "overlap": sorted(set(train) & set(test)),
            "predictions": predictions, "accuracy": accuracy}


# Verification: declared target is unseen groups, not arbitrary new rows.
assert evaluate("row")["accuracy"] == 1
assert evaluate("row")["overlap"] == list("ABCD")
assert evaluate("group")["accuracy"] == 0.5
assert evaluate("group")["overlap"] == []
fixtures = [{"inputs": {"split": s}, "expected": evaluate(s)}
            for s in ("row", "group")]

import json
print(json.dumps({"fixtures": fixtures, "checks_passed": True}))
