Skip to content

tests: a game_gate case where the median is not the fastest half - #2794

Open
fiestorra wants to merge 1 commit into
ProjectLeonida:mainfrom
fiestorra:game-gate-varying-rate
Open

fiestorra wants to merge 1 commit into
ProjectLeonida:mainfrom
fiestorra:game-gate-varying-rate

Conversation

@fiestorra

Copy link
Copy Markdown
Contributor

The game_gate suite cannot currently tell a median from a maximum. This adds the case that can, and it is one test.

The gap, found by mutation on #2782 before it merged: replacing statistics.median() with max() in parse_frames (both sites, tools/game_gate.py:291 and :311) left all 20 tests passing. The reason is in the fixtures: every case writes one frame rate, so for each of them median == mean == max, and assertAlmostEqual(s["fps"]["median"], 50.0) is satisfied by any of the three.

That is now in main, since #2782 merged - so the assertion that reads "median" is not testing a median.

The case added:

f.frames(70, 130, 50.0, 4000)      # the world, first minute: not counted
f.frames(130, 190, 40.0, 4000)     # counted: 60 s at 25 ms a frame, 2400 presents
f.frames(190, 230, 60.0, 4000)     # counted: 40 s at 16.67 ms a frame, 2400 presents
...
assertAlmostEqual(s["fps"]["median"], 48.0, delta=1.0)
assertAlmostEqual(s["fps"]["p5"], 40.0, delta=1.0)

The windows are unequal on purpose and the presents are equal: 60 s at 40 fps and 40 s at 60 fps both give 2400 gaps, so the median gap is the mean of 16.67 and 25 ms - 48 fps - while max() answers 1000 / 25 = 40. Equal durations would not have worked: the 60 fps half contributes 9000 presents to 6000, the median lands on 16.67, and the case reads 60 for both implementations. I tried that first and it passed the mutation.

Measured, both arms:

python -m pytest tests/test_game_gate.py -q
  correct code:   22 passed
  with max():      1 failed - AssertionError: 40.0 != 48.0 within 1.0 delta

So the mutation now fails on this case and the other 21 still pass - the case is pointed, which is what a regression test for a statistic should be.

p5 is asserted too, because it is the other place a rate statistic is derived and it was equally indistinguishable: percentile(counted, 95) reads the slow half (40 fps) here.

One file, +16/-0, no tool code touched.

AI-assisted: yes - DeepSeek v4.1 (flash). Found while reviewing #2782, whose author merged with the note on record; this closes it rather than re-litigating it.

Written with an AI assistant.

Every fixture in the file writes one frame rate, so median, mean and maximum were the samenumber and replacing statistics.median() with max() in parse_frames left all 21 passing. This
adds two halves with equal presents - 60 s at 40 fps and 40 s at 60 fps, 2400 each - so the median
gap sits between the two and reads 48, while max() answers 40. Measured: with the mutation the
case fails 40.0 != 48.0, and the other 21 still pass, so the case is pointed rather than
collateral.
@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, head a2b1f1c93, main 0b6e0e3bc. CPU only, no game files.

MEASURED

  • This PR only adds a test, so red and green run the same code: tests/test_game_gate.py gives 22 passed on main + this test, and 22 passed on main + the PR (merge-tree).
  • Mutation, run on the PR head: every statistics.median( in tools/game_gate.py (lines 279, 291, 296, 312, 315) replaced with max( gives 1 failed, 21 passed. The only failure is the new test_the_median_is_not_the_fastest_half (40.0 != 48.0 within 1.0 delta). That matches your result, and it also holds when all five sites are mutated, not just the two in parse_frames.

READ IN CODE

  • The fixture uses equal present counts (2400 each) over unequal durations, so the median gap sits between 25 ms and 16.67 ms. That is the property the test needs.

AI-assisted: Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants