From a2b1f1c9380ecba5dd086f7231dfef1721806602 Mon Sep 17 00:00:00 2001 From: fiestorra Date: Mon, 30 Nov 2026 22:35:19 +0100 Subject: [PATCH] tests: a game_gate case where the median is not the fastest half 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. --- tests/test_game_gate.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_game_gate.py b/tests/test_game_gate.py index 879419d5da..3356e4687f 100644 --- a/tests/test_game_gate.py +++ b/tests/test_game_gate.py @@ -194,6 +194,22 @@ def test_percentiles_come_from_the_presents(self): self.assertAlmostEqual(s["fps"]["end_median"], 25.0, delta=0.3) self.assertIsNone(s["fps"]["under_2_at_s"]) + def test_the_median_is_not_the_fastest_half(self): + # Every fixture in this file writes one frame rate, so median, mean and maximum were the same number and + # replacing statistics.median() with max() in parse_frames left all of them passing. This case has two + # halves: 40 fps and then 60, equal in length, so the median gap sits between the two and the a + # that gets read as a median is 48, while max() would answer 40 (1000 / the longest gap). + f = Fake() + f.event(1, "game", pid=1) + 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 + f.clean_stop(430) + s = f.summarize() + self.assertAlmostEqual(s["fps"]["median"], 48.0, delta=1.0, + msg="the median of two equal halves is between them, not the slowest one") + # The two halves are visible in the other statistics too: the 5th percentile of fps is the slow half. + self.assertAlmostEqual(s["fps"]["p5"], 40.0, delta=1.0) def test_a_dip_on_arrival_is_not_the_first_second_under_2(self): # One frame a second just after the world (streaming in), then steady, then a dip later on: under_2_at_s # counts from 60 s in the world, like the median, and finds the later dip.