nordic-skating / files / test / settings.test.ts
settings.test.ts
a8fd3f13 2026-10-10 Pavel Safronov | 1 | import { describe, expect, it } from 'vitest' |
| 2 | import { TIME_NAMES } from '../src/render/sky.js' | |
236f7d03 2026-10-10 Pavel Safronov | 3 | import { WEATHER, WEATHERS, anyLake, loadSettings, timeOf, weatherOf, windOf } from '../src/settings.js' |
a8fd3f13 2026-10-10 Pavel Safronov | 4 | |
| 5 | describe('settings', () => { | |
8876a48d 2026-10-10 Pavel Safronov | 6 | it('starts with a surprise for the time of day, no impossible ice, and steering by touch', () => { |
a8fd3f13 2026-10-10 Pavel Safronov | 7 | // There is no storage here, which is also what a private window is like. |
1ee103b4 2026-10-11 Pavel Safronov | 8 | expect(loadSettings()).toEqual({ time: 'surprise', weather: 'surprise', pace: 'cruise', impossibleIce: false, tilt: false }) |
a8fd3f13 2026-10-10 Pavel Safronov | 9 | }) |
| 10 | ||
| 11 | it('picks a lake from a million', () => { | |
| 12 | for (let i = 0; i < 1000; i++) { | |
| 13 | const lake = anyLake() | |
| 14 | expect(Number.isInteger(lake)).toBe(true) | |
| 15 | expect(lake).toBeGreaterThanOrEqual(1) | |
| 16 | expect(lake).toBeLessThanOrEqual(999_999) | |
| 17 | } | |
| 18 | }) | |
| 19 | ||
| 20 | it('gives each lake a time of day of its own: every time somewhere, day the likeliest', () => { | |
| 21 | const count = Object.fromEntries(TIME_NAMES.map((name) => [name, 0])) | |
| 22 | for (let lake = 1; lake <= 20_000; lake++) { | |
| 23 | expect(timeOf(lake)).toBe(timeOf(lake)) | |
| 24 | count[timeOf(lake)]!++ | |
| 25 | } | |
| 26 | for (const name of TIME_NAMES) expect(count[name]! / 20_000).toBeGreaterThan(0.12) | |
| 27 | expect(count.day).toBe(Math.max(...Object.values(count))) | |
| 28 | expect(count.aurora).toBe(Math.min(...Object.values(count))) | |
| 29 | }) | |
236f7d03 2026-10-10 Pavel Safronov | 30 | |
| 31 | it('gives each lake a weather of its own: mostly clear, sometimes snow, now and then a blizzard', () => { | |
| 32 | const count = Object.fromEntries(WEATHERS.map((name) => [name, 0])) | |
| 33 | for (let lake = 1; lake <= 20_000; lake++) { | |
| 34 | expect(weatherOf(lake)).toBe(weatherOf(lake)) | |
| 35 | count[weatherOf(lake)]!++ | |
| 36 | expect(windOf(lake)).toBeGreaterThanOrEqual(0) | |
| 37 | expect(windOf(lake)).toBeLessThan(2 * Math.PI) | |
| 38 | } | |
| 39 | expect(count.clear! / 20_000).toBeGreaterThan(0.55) | |
| 40 | expect(count.snow! / 20_000).toBeGreaterThan(0.2) | |
| 41 | expect(count.blizzard! / 20_000).toBeGreaterThan(0.06) | |
| 42 | expect(count.blizzard).toBeLessThan(count.snow!) | |
| 43 | }) | |
| 44 | ||
| 45 | it('has weather that gets worse in every way together', () => { | |
| 46 | const [clear, falling, blizzard] = WEATHERS.map((name) => WEATHER[name]) | |
| 47 | expect(clear!.snow).toBe(0) | |
| 48 | expect(clear!.wind[1]).toBe(0) | |
| 49 | for (const [milder, worse] of [[clear!, falling!], [falling!, blizzard!]] as const) { | |
| 50 | expect(worse.snow).toBeGreaterThan(milder.snow) | |
| 51 | expect(worse.sight).toBeLessThan(milder.sight) | |
| 52 | expect(worse.overcast).toBeGreaterThan(milder.overcast) | |
| 53 | expect(worse.wind[1]).toBeGreaterThan(milder.wind[1]) | |
| 54 | } | |
| 55 | }) | |
a8fd3f13 2026-10-10 Pavel Safronov | 56 | }) |