"""Zero-dep tests for genotype.py GEN-3b normalization.

Run: python test_genotype.py   (exit 0 = all pass)
Covers: Uw/uw -> G/g alias, Sls/WP second spotting locus, dea/Dea/taub
hearing-deaf flag, WFNZ/RV/GV/DP provenance tags. Per hive/agents/god/GENETIK-notation.md.
"""
import sys
import genotype as g


def check(name, cond):
    if not cond:
        print(f"FAIL: {name}")
        check.failed += 1
    else:
        print(f"ok:   {name}")
check.failed = 0


# --- Uw/uw == G/g (same locus) ---
r = g.parse("aa Cc Dd Ee Uwuw Pp spsp rere")
check("Uw->G: G locus mapped", r["mapped8locus"].get("G") == ["G", "g"])
check("Uw->G: nothing left in unmapped", r["unmappedTokens"] == [])

r = g.parse("UwUw")
check("UwUw -> GG", r["mapped8locus"].get("G") == ["G", "G"])
r = g.parse("uwuw")
check("uwuw -> gg", r["mapped8locus"].get("G") == ["g", "g"])
r = g.parse("uw[d]uw[d]")
check("uw[d]uw[d] -> gg (dense underwhite)", r["mapped8locus"].get("G") == ["g", "g"])

# Gg and Uwuw must produce the SAME mapped locus (so they stop being a conflict)
check("Gg identical to Uwuw at G locus",
      g.parse("Gg")["mapped8locus"]["G"] == g.parse("Uwuw")["mapped8locus"]["G"])

# --- Sls / WP second spotting locus ---
check("WP -> Sls het", g.parse("WP")["mapped8locus"].get("Sls") == ["Sl", "sl"])
check("[WP] (bracketed) -> Sls het", g.parse("[WP]")["mapped8locus"].get("Sls") == ["Sl", "sl"])
check("Sls token -> Sls het", g.parse("Sls")["mapped8locus"].get("Sls") == ["Sl", "sl"])
check("sls -> Sls wild", g.parse("sls")["mapped8locus"].get("Sls") == ["sl", "sl"])
check("S(l)s(l) -> Sl,sl", g.parse("S(l)s(l)")["mapped8locus"].get("Sls") == ["Sl", "sl"])
# Sp and Sls are TWO distinct loci on the same animal (Superschecke)
r = g.parse("spsp WP")
check("Sp + Sls coexist (two spotting loci)",
      r["mapped8locus"].get("Sp") == ["sp", "sp"] and r["mapped8locus"].get("Sls") == ["Sl", "sl"])

# --- deafness flag (after spsp), case-sensitive ---
check("dea (lower) -> deaf True", g.parse("spsp dea")["deaf"] is True)
check("taub -> deaf True", g.parse("taub")["deaf"] is True)
check("Dea (upper) -> hearing False", g.parse("spsp Dea")["deaf"] is False)
check("(hörend) -> hearing False", g.parse("(hörend)")["deaf"] is False)
check("no deaf token -> None", g.parse("aa Cc")["deaf"] is None)
# deafness is NOT a genotype locus and must not pollute mapped/unmapped silently
check("deaf flag not in unmapped", "dea" not in g.parse("spsp dea")["unmappedTokens"])

# --- provenance / breeding tags (never genotype, never conflict) ---
check("WFNZ -> tag", g.parse("aa WFNZ")["tags"] == ["WFNZ"])
check("RV -> tag", g.parse("(RV)")["tags"] == ["RV"])
check("GV -> tag", g.parse("(GV)")["tags"] == ["GV"])
check("DP -> tag", g.parse("[DP]")["tags"] == ["DP"])
check("tag not in genotype loci", g.parse("WFNZ")["mapped8locus"] == {})
check("tag not in unmapped", g.parse("aa WFNZ")["unmappedTokens"] == [])

# --- looks_like_genotype recognizes Uw-bearing cells ---
check("looks_like_genotype sees Uw as G",
      g.looks_like_genotype("aa Cc Uwuw") is True)

if check.failed:
    print(f"\n{check.failed} test(s) FAILED")
    sys.exit(1)
print("\nALL PASS")
