diff options
| author | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
|---|---|---|
| committer | godosa <godosa@godosa.eu> | 2026-10-07 00:14:38 +0200 |
| commit | 3443c1c65e9f1753e1e656b35d08416c1fa298f2 (patch) | |
| tree | 4e43236f460145a4d75d1b4616dcb7aa6ef08f51 /viewer/tests/sky.test.mjs | |
| download | worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.tar.gz worldmap-viewer-3443c1c65e9f1753e1e656b35d08416c1fa298f2.zip | |
worldmap-viewer: initial public history
Diffstat (limited to 'viewer/tests/sky.test.mjs')
| -rw-r--r-- | viewer/tests/sky.test.mjs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/viewer/tests/sky.test.mjs b/viewer/tests/sky.test.mjs new file mode 100644 index 0000000..836508b --- /dev/null +++ b/viewer/tests/sky.test.mjs @@ -0,0 +1,38 @@ +import './_planet.mjs'; +import { test } from 'node:test'; +import assert from 'node:assert/strict'; +import { subsolar, sunVec, dayFraction, seasonName, DAY_MOMENTS } from '../js/sky.js'; +import { toLatLon } from '../js/geo.js'; + +const near = (a, b, eps) => assert.ok(Math.abs(a - b) <= eps, `${a} vs ${b}`); + +test('sub-solar latitude follows the 20° tilt over the 216-day year', () => { + near(subsolar(0, 0).lat, 0, 1e-9); + near(subsolar(54, 0).lat, 20, 1e-9); + near(subsolar(108, 0).lat, 0, 1e-9); + near(subsolar(162, 0).lat, -20, 1e-9); +}); + +test('sub-solar longitude: noon at 0° at moment 23,328, midnight at 0° at moment 0', () => { + near(subsolar(0, DAY_MOMENTS / 2).lon, 0, 1e-9); + near(Math.abs(subsolar(0, 0).lon), 180, 1e-9); + near(subsolar(0, DAY_MOMENTS / 4).lon, 90, 1e-9); + const v = toLatLon(sunVec(54, DAY_MOMENTS / 2)); + near(v.lat, subsolar(54, DAY_MOMENTS / 2).lat, 1e-6); +}); + +test('day length', () => { + near(dayFraction(0, 30), 0.5, 1e-9); + assert.equal(dayFraction(80, 54), 1); + assert.equal(dayFraction(80, 162), 0); + assert.equal(dayFraction(-80, 54), 0); + assert.equal(dayFraction(90, 0), 0.5); + assert.ok(dayFraction(45, 54) > 0.5 && dayFraction(45, 162) < 0.5); +}); + +test('season names near the equinoxes and solstices only', () => { + assert.equal(seasonName(0), 'northern spring equinox'); + assert.equal(seasonName(55), 'northern midsummer'); + assert.equal(seasonName(215), 'northern spring equinox'); + assert.equal(seasonName(30), ''); +}); |
