|
| 1 | +"""Boundary conditions for the Cat 2c multi-hop verdict. |
| 2 | +
|
| 3 | +``test_multi_hop.py`` already covers the clear-cut verdict cases (a solid |
| 4 | +win, a solid loss, a clean neutral tax). What it does *not* pin are the |
| 5 | +threshold boundaries — and the verdict uses strict inequalities at three |
| 6 | +of them, so a value sitting exactly on the line is silently classified |
| 7 | +the *other* way from what a casual reader expects: |
| 8 | +
|
| 9 | + * "beats A" requires recall_delta_pp **> 5**, so a +5.0pp delta does |
| 10 | + NOT count as a win. |
| 11 | + * "loses to A" requires recall_delta_pp **< -5**, so a -5.0pp delta |
| 12 | + does NOT count as a loss. |
| 13 | + * "ratio grows" requires last **> first * 1.2**, so a ratio that lands |
| 14 | + exactly on first*1.2 is "uniform scale", not "earns complexity". |
| 15 | +
|
| 16 | +These off-by-epsilon boundaries are precisely where a verdict would flip |
| 17 | +under a tiny measurement perturbation, so they are worth nailing down. |
| 18 | +The expected verdicts were verified against the live ``_verdict`` before |
| 19 | +being pinned here. |
| 20 | +""" |
| 21 | +from __future__ import annotations |
| 22 | + |
| 23 | +from sme.categories.multi_hop import Cat2cReport, _verdict |
| 24 | + |
| 25 | + |
| 26 | +def _report(deltas_a, ratios, deltas_c=None) -> Cat2cReport: |
| 27 | + r = Cat2cReport() |
| 28 | + r.delta_B_minus_A = deltas_a |
| 29 | + r.ratio_B_over_A = ratios |
| 30 | + if deltas_c is not None: |
| 31 | + r.delta_B_minus_C = deltas_c |
| 32 | + return r |
| 33 | + |
| 34 | + |
| 35 | +# ── ±5pp win/loss boundaries (strict inequality) ────────────────── |
| 36 | + |
| 37 | + |
| 38 | +def test_exactly_plus_5pp_is_not_a_win(): |
| 39 | + """+5.0pp at every depth is on the boundary; the strict ``> 5`` test |
| 40 | + means it doesn't count as beating flat → neutral tax, not a win.""" |
| 41 | + r = _report( |
| 42 | + {1: {"recall_delta_pp": 5.0, "tokens_delta": 0}, |
| 43 | + 2: {"recall_delta_pp": 5.0, "tokens_delta": 0}}, |
| 44 | + {1: 1.05, 2: 1.05}, |
| 45 | + ) |
| 46 | + assert _verdict(r)[0] == "structure is a neutral tax" |
| 47 | + |
| 48 | + |
| 49 | +def test_exactly_minus_5pp_is_not_a_loss(): |
| 50 | + """-5.0pp is on the boundary; the strict ``< -5`` test means it |
| 51 | + doesn't count as losing → neutral tax, not harmful.""" |
| 52 | + r = _report( |
| 53 | + {1: {"recall_delta_pp": -5.0, "tokens_delta": 0}}, |
| 54 | + {1: 0.95}, |
| 55 | + ) |
| 56 | + assert _verdict(r)[0] == "structure is a neutral tax" |
| 57 | + |
| 58 | + |
| 59 | +def test_just_over_5pp_is_a_win(): |
| 60 | + """5.01pp clears the boundary → counts as beating flat.""" |
| 61 | + r = _report( |
| 62 | + {1: {"recall_delta_pp": 5.01, "tokens_delta": 0}, |
| 63 | + 2: {"recall_delta_pp": 5.01, "tokens_delta": 0}}, |
| 64 | + {1: 1.05, 2: 1.05}, # flat ratio → uniform scale, but it IS a win |
| 65 | + ) |
| 66 | + assert _verdict(r)[0] == "structure adds value at uniform scale" |
| 67 | + |
| 68 | + |
| 69 | +def test_just_under_minus_5pp_is_a_loss(): |
| 70 | + """-5.01pp clears the boundary the other way → counts as a loss.""" |
| 71 | + r = _report( |
| 72 | + {1: {"recall_delta_pp": -5.01, "tokens_delta": 0}}, |
| 73 | + {1: 0.9}, |
| 74 | + ) |
| 75 | + assert _verdict(r)[0] == "structure harmful at multi-hop" |
| 76 | + |
| 77 | + |
| 78 | +# ── ratio-grows boundary (last > first * 1.2) ───────────────────── |
| 79 | + |
| 80 | + |
| 81 | +def test_ratio_exactly_at_1_2x_does_not_grow(): |
| 82 | + """last == first * 1.2 is on the boundary; the strict ``>`` means the |
| 83 | + ratio is NOT considered to grow → uniform scale, not earns-complexity.""" |
| 84 | + r = _report( |
| 85 | + {1: {"recall_delta_pp": 10.0, "tokens_delta": 0}, |
| 86 | + 2: {"recall_delta_pp": 10.0, "tokens_delta": 0}}, |
| 87 | + {1: 1.0, 2: 1.2}, # 1.2 == 1.0 * 1.2 exactly |
| 88 | + ) |
| 89 | + assert _verdict(r)[0] == "structure adds value at uniform scale" |
| 90 | + |
| 91 | + |
| 92 | +def test_ratio_just_over_1_2x_earns_complexity(): |
| 93 | + """last just past first * 1.2 → ratio grows → earns complexity.""" |
| 94 | + r = _report( |
| 95 | + {1: {"recall_delta_pp": 10.0, "tokens_delta": 0}, |
| 96 | + 2: {"recall_delta_pp": 40.0, "tokens_delta": 0}}, |
| 97 | + {1: 1.0, 2: 1.21}, |
| 98 | + ) |
| 99 | + assert _verdict(r)[0] == "structure earns complexity (scales with depth)" |
| 100 | + |
| 101 | + |
| 102 | +# ── single-ratio guard (ratio_grows needs >= 2 points) ──────────── |
| 103 | + |
| 104 | + |
| 105 | +def test_single_hop_ratio_cannot_grow(): |
| 106 | + """With only one hop bucket the ratio has nothing to grow against, so |
| 107 | + a win is reported as uniform scale, never earns-complexity.""" |
| 108 | + r = _report( |
| 109 | + {1: {"recall_delta_pp": 50.0, "tokens_delta": 0}}, |
| 110 | + {1: 5.0}, # huge but single-point → ratio_grows stays False |
| 111 | + ) |
| 112 | + assert _verdict(r)[0] == "structure adds value at uniform scale" |
| 113 | + |
| 114 | + |
| 115 | +# ── infinite-ratio entries are skipped in the grows check ───────── |
| 116 | + |
| 117 | + |
| 118 | +def test_infinite_ratio_skipped_in_grows_check(): |
| 119 | + """An inf ratio (A had zero recall at a depth) is excluded from the |
| 120 | + grows comparison; the remaining finite points decide it. Here only |
| 121 | + one finite ratio survives, so it can't grow → uniform scale.""" |
| 122 | + r = _report( |
| 123 | + {1: {"recall_delta_pp": 60.0, "tokens_delta": 0}, |
| 124 | + 2: {"recall_delta_pp": 70.0, "tokens_delta": 0}}, |
| 125 | + {1: float("inf"), 2: 3.0}, |
| 126 | + ) |
| 127 | + assert _verdict(r)[0] == "structure adds value at uniform scale" |
| 128 | + |
| 129 | + |
| 130 | +# ── C-absent narration when A is present ────────────────────────── |
| 131 | + |
| 132 | + |
| 133 | +def test_no_c_overlap_still_notes_missing_isolation(): |
| 134 | + """A populated but no B-C overlap → the verdict still narrates that |
| 135 | + the structural contribution could not be isolated, so the reader |
| 136 | + isn't misled into thinking C was tested.""" |
| 137 | + r = _report( |
| 138 | + {1: {"recall_delta_pp": 10.0, "tokens_delta": 0}}, |
| 139 | + {1: 1.3}, |
| 140 | + ) |
| 141 | + verdict, details = _verdict(r) |
| 142 | + assert verdict == "structure adds value at uniform scale" |
| 143 | + assert any("no Condition C" in d for d in details) |
0 commit comments