From f77b5fca7435273a7d0fb4163ad189b375da8b08 Mon Sep 17 00:00:00 2001 From: Chris Parsons Date: Wed, 25 Mar 2026 08:42:01 -0700 Subject: [PATCH] Fix flaky tennis simulator test: increase trials and lower threshold MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 500 trials with a ~3–5% expected win rate had enough variance to occasionally land below the 0.03 threshold (~2% failure rate). Bumping to 2000 trials reduces the std dev by 2x; lowering the threshold to 0.02 keeps the assertion meaningful (still well above random 0.78%) while eliminating the flakiness. Co-Authored-By: Claude Sonnet 4.6 --- .../simulations/__tests__/tennis-simulator.test.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/services/simulations/__tests__/tennis-simulator.test.ts b/app/services/simulations/__tests__/tennis-simulator.test.ts index 166dbbe..fa23b5c 100644 --- a/app/services/simulations/__tests__/tennis-simulator.test.ts +++ b/app/services/simulations/__tests__/tennis-simulator.test.ts @@ -265,7 +265,7 @@ describe("QP accumulation ranking (unit)", () => { const eloMap = makeEloMap(IDS, elos); let seed1Wins = 0; - const TRIALS = 500; + const TRIALS = 2000; for (let i = 0; i < TRIALS; i++) { const draw = buildDraw(IDS, eloMap); const results = simulateMajor(draw, eloMap, "hard"); @@ -273,9 +273,10 @@ describe("QP accumulation ranking (unit)", () => { if (seed1?.qp === 20) seed1Wins++; } - // Seed 1 has ~3 points advantage per player; against 127 opponents should win - // substantially more than 1/128 ≈ 0.78% of the time + // Seed 1 has ~3 Elo points advantage per seed; should win substantially + // more than 1/128 ≈ 0.78% of the time. Threshold at 0.02 is still well + // above random; 2000 trials keeps std dev small enough to be non-flaky. const winRate = seed1Wins / TRIALS; - expect(winRate).toBeGreaterThan(0.03); // > 3% (well above random 0.78%) + expect(winRate).toBeGreaterThan(0.02); // > 2% (well above random 0.78%) }); });