From 3443c1c65e9f1753e1e656b35d08416c1fa298f2 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 00:14:38 +0200 Subject: worldmap-viewer: initial public history --- viewer/tests/sky.test.mjs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 viewer/tests/sky.test.mjs (limited to 'viewer/tests/sky.test.mjs') 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), ''); +}); -- cgit