"""
Practice: the counts behind Lab 09, which asks whether reading an AI review's comments first makes a
reviewer miss what the AI missed. You'll write the paired comparison (bugs lost and gained between two
conditions), its sign test, the "found in both runs alone, missed with the AI's comments" count, the
split by what the AI said, and team recall assumed independent vs measured.

Every reviewer here is an AI model standing in for a person. A "found" dict maps a PR id to 1 when the
reviewer's comments found that PR's planted bug, 0 when they missed it. PR ids look like "c08-d1": the
change ("c08"), then the copy with planted bug 1 ("d1").

Fill in the TODOs, then run the tests:
    pytest test_bias_practice.py        (locally)
or press "Run tests" on the chapter page.
"""


def paired(a: dict[str, int], b: dict[str, int]) -> tuple[int, int]:
    """Compare condition B with condition A on the same bugs: return (lost, gained).

    Only PRs present in both dicts count. lost = found under A, missed under B.
    gained = missed under A, found under B. Bugs found (or missed) under both don't count."""
    # TODO
    raise NotImplementedError


def sign_test_p(lost: int, gained: int) -> float:
    """Two-sided exact sign test on the discordant pairs (McNemar's exact test).

    With n = lost + gained and k = min(lost, gained): p = 2 * sum(C(n, i) for i in 0..k) / 2**n,
    capped at 1.0. Return 1.0 when n is 0. (math.comb is in the standard library.)"""
    # TODO
    raise NotImplementedError


def found_twice_then_missed(run1: dict[str, int], run2: dict[str, int], other: dict[str, int]) -> tuple[int, int]:
    """Bugs the reviewer found in both runs alone, and how many of those it missed under `other`.

    Return (found in both run1 and run2, of those missed in `other`). Skip PRs missing from `other`."""
    # TODO
    raise NotImplementedError


def by_ai_message(alone: dict[str, int], with_ai: dict[str, int], silent: set[str]) -> dict[str, tuple[int, int, int]]:
    """Split the bugs by what the AI posted on that PR: nothing ("silent") or comments about something
    else ("other"). For each group return (bugs, found alone, found with the AI's comments)."""
    # TODO
    raise NotImplementedError


def team_recall(ai_found: int, alone: dict[str, int], with_ai: dict[str, int]) -> tuple[int, int]:
    """Bugs the AI review and a reviewer catch together, two ways: (assumed independent, measured).

    ai_found is how many bugs the AI review found; on those the team catches the bug whatever the
    reviewer does. `alone` and `with_ai` cover only the bugs the AI missed. Assumed independent, the
    reviewer finds what they find alone; measured, what they find after reading the AI's comments."""
    # TODO
    raise NotImplementedError
