-- constellation.sql -- Tests for v0.14.0: IAU constellation identification -- -- Verifies the Roman (1987) boundary lookup against well-known -- stellar positions and solar system objects. CREATE EXTENSION IF NOT EXISTS pg_orrery; NOTICE: extension "pg_orrery" already exists, skipping -- ============================================================ -- Known stars via J2000 RA/Dec overload -- ============================================================ -- Polaris (Alpha UMi): RA 2.5303h, Dec +89.264 SELECT constellation(2.5303, 89.264) AS polaris_constellation; polaris_constellation ----------------------- UMi (1 row) -- Sirius (Alpha CMa): RA 6.7525h, Dec -16.716 SELECT constellation(6.7525, -16.716) AS sirius_constellation; sirius_constellation ---------------------- CMa (1 row) -- Betelgeuse (Alpha Ori): RA 5.9195h, Dec +7.407 SELECT constellation(5.9195, 7.407) AS betelgeuse_constellation; betelgeuse_constellation -------------------------- Ori (1 row) -- Vega (Alpha Lyr): RA 18.6156h, Dec +38.784 SELECT constellation(18.6156, 38.784) AS vega_constellation; vega_constellation -------------------- Lyr (1 row) -- Antares (Alpha Sco): RA 16.4901h, Dec -26.432 SELECT constellation(16.4901, -26.432) AS antares_constellation; antares_constellation ----------------------- Sco (1 row) -- Deneb (Alpha Cyg): RA 20.6905h, Dec +45.280 SELECT constellation(20.6905, 45.280) AS deneb_constellation; deneb_constellation --------------------- Cyg (1 row) -- Rigel (Beta Ori): RA 5.2423h, Dec -8.202 SELECT constellation(5.2423, -8.202) AS rigel_constellation; rigel_constellation --------------------- Ori (1 row) -- ============================================================ -- Celestial poles -- ============================================================ -- South celestial pole -> Octans SELECT constellation(0.0, -90.0) AS south_pole_constellation; south_pole_constellation -------------------------- Oct (1 row) -- Near north celestial pole -> Ursa Minor SELECT constellation(0.0, 89.0) AS north_pole_constellation; north_pole_constellation -------------------------- UMi (1 row) -- ============================================================ -- Solar system objects via equatorial overload -- ============================================================ -- Sun at 2024 summer solstice should be in Gemini (not Cancer -- -- precession has shifted the solstice point) SELECT constellation(sun_equatorial('2024-06-21 12:00:00+00'::timestamptz)) AS sun_solstice_constellation; sun_solstice_constellation ---------------------------- Gem (1 row) -- Jupiter in Jan 2024 should be in Aries SELECT constellation(planet_equatorial(5, '2024-01-15 12:00:00+00'::timestamptz)) AS jupiter_jan2024_constellation; jupiter_jan2024_constellation ------------------------------- Ari (1 row) -- ============================================================ -- Both overloads should agree for the same position -- ============================================================ SELECT constellation(18.6156, 38.784) = constellation(make_equatorial(18.6156, 38.784, 0.0)) AS overloads_agree; overloads_agree ----------------- t (1 row) -- ============================================================ -- RA boundary edge case near 0h/24h wrap -- ============================================================ -- RA just above 0h at various declinations SELECT constellation(0.01, 45.0) IS NOT NULL AS ra_near_zero_valid; ra_near_zero_valid -------------------- t (1 row) SELECT constellation(23.99, -30.0) IS NOT NULL AS ra_near_24_valid; ra_near_24_valid ------------------ t (1 row) -- ============================================================ -- Error cases -- ============================================================ -- RA out of range DO $$ BEGIN PERFORM constellation(24.1, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'RA=24.1: %', SQLERRM; END $$; NOTICE: RA=24.1: constellation: RA must be in [0, 24), got 24.1000 DO $$ BEGIN PERFORM constellation(-0.1, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'RA=-0.1: %', SQLERRM; END $$; NOTICE: RA=-0.1: constellation: RA must be in [0, 24), got -0.1000 -- Dec out of range DO $$ BEGIN PERFORM constellation(12.0, 91.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'Dec=91: %', SQLERRM; END $$; NOTICE: Dec=91: constellation: Dec must be in [-90, 90], got 91.0000