1/**2 * HUD distance milestones: thresholds are a pure function of the arc3 * interval crossed this frame (hud.ts milestoneFor). Race place is a4 * pure count of racers strictly ahead (hud.ts racePlace).5 */6import { assert, assertEquals } from "@std/assert";7import { milestoneFor, racePlace } from "../src/client/hud.ts";89Deno.test("milestones: landmark thresholds then every 500", () => {10 assertEquals(milestoneFor(99, 100.5), 100);11 assertEquals(milestoneFor(100, 101), null);12 assertEquals(milestoneFor(240, 260), 250);13 assertEquals(milestoneFor(999, 1001), 1000);14 assertEquals(milestoneFor(1200, 1300), null);15 assertEquals(milestoneFor(1499, 1500), 1500);16 assertEquals(milestoneFor(7400, 7501), 7500);17 // A big skip reports the LAST threshold crossed.18 assertEquals(milestoneFor(0, 2600), 2500);19});2021Deno.test("milestones: never fire backward or in place", () => {22 assertEquals(milestoneFor(500, 500), null);23 assertEquals(milestoneFor(600, 400), null);24 // Respawn jump backward then forward again re-crosses honestly.25 assert(milestoneFor(400, 501) === 500);26});2728Deno.test("milestones: dense stepping never skips a threshold", () => {29 let s = 0;30 const seen: number[] = [];31 while (s < 3000) {32 const next = s + 0.9;33 const m = milestoneFor(s, next);34 if (m !== null) seen.push(m);35 s = next;36 }37 assertEquals(38 seen,39 [100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000].filter((m) => m <= s),40 );41});4243Deno.test("race place: 1 + racers strictly ahead", () => {44 // Leading the pack.45 assertEquals(racePlace(50, [50, 10, 30]), 1);46 // Mid-pack: two ahead.47 assertEquals(racePlace(30, [30, 50, 40, 10]), 3);48 // Dead last.49 assertEquals(racePlace(0, [0, 1, 2, 3]), 4);50});5152Deno.test("race place: ties share the better place, hero self-safe", () => {53 // Including the hero's own s never counts it as ahead of itself.54 assertEquals(racePlace(25, [25]), 1);55 // An exact tie is not "ahead" — both read the better place.56 assertEquals(racePlace(25, [25, 25, 40]), 2);57 // Solo race (no peers passed at all).58 assertEquals(racePlace(7, []), 1);59});6061Deno.test("race place: big field stays exact", () => {62 const n = 9999;63 const all = Array.from({ length: n }, (_, i) => i);64 // Hero at progress 4999 -> 5000..9998 are ahead (4999 of them).65 assertEquals(racePlace(4999, all), 5000);66 assertEquals(racePlace(n - 1, all), 1);67 assertEquals(racePlace(-1, all), n + 1);68});