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), ''); });