fuzzyworld

tower / files / test / eye-gauge.test.ts

eye-gauge.test.ts

1.5 KB · history · blame

1import { describe, expect, it } from 'vitest'
2import { LANDMARKS, compareHeight, fmtM } from '../src/ui/eye-gauge.js'
3import { EYE_MAX_M, EYE_MIN_M } from '../src/ui/scales.js'
4
5describe('the eye-height gauge (D-082)', () => {
6 it('marks things of known height, low to high, all on the scale', () => {
7 for (let i = 1; i < LANDMARKS.length; i++) expect(LANDMARKS[i]!.m).toBeGreaterThan(LANDMARKS[i - 1]!.m)
8 for (const l of LANDMARKS) {
9 expect(l.m).toBeGreaterThanOrEqual(EYE_MIN_M)
10 expect(l.m).toBeLessThanOrEqual(EYE_MAX_M)
11 }
12 })
13
14 it('says a height is level with a landmark within a tenth of it', () => {
15 expect(compareHeight(330)).toBe('≈ the Eiffel Tower')
16 expect(compareHeight(355)).toBe('≈ the Eiffel Tower')
17 expect(compareHeight(1.7)).toBe('≈ an adult')
18 })
19
20 it('otherwise gives a multiple of the highest landmark passed', () => {
21 expect(compareHeight(660)).toBe('2.0× the Eiffel Tower')
22 expect(compareHeight(4)).toBe('2.4× an adult')
23 expect(compareHeight(40_000)).toBe('1.1× a weather balloon')
24 })
25
26 it('tops out at the beam, as high as anyone can go (D-084)', () => {
27 expect(LANDMARKS.at(-1)).toEqual({ m: EYE_MAX_M, name: 'the beam' })
28 expect(EYE_MAX_M).toBeCloseTo(48_408, 0)
29 expect(compareHeight(48_000)).toBe('≈ the beam')
30 })
31
32 it('prints metres and kilometres as the readouts do', () => {
33 expect(fmtM(1.7)).toBe('1.7 m')
34 expect(fmtM(330.4)).toBe('330 m')
35 expect(fmtM(8849)).toBe('8.8 km')
36 })
37})