pg_orrery/test/sql/v013_features.sql
Ryan Malloy a349f5505a Add v0.13.0: nutation, make_equatorial constructor, rise/set predictions
Integrate IAU 2000B nutation (~9 arcsec) into the solar system observation
pipeline via precess_and_nutate_j2000_to_date(). Affects all planet, star,
moon, and small body RA/Dec and az/el values. Satellite SGP4/TEME pipeline
unchanged.

Add make_equatorial(ra_hours, dec_deg, distance_km) constructor to replace
error-prone text literal casts.

Add 8 rise/set prediction functions (planet_next_rise/set, sun_next_rise/set,
moon_next_rise/set, sun_next_rise/set_refracted) using bisection algorithm
adapted from satellite pass prediction. Returns NULL for circumpolar and
polar night edge cases.

Fix DE fallback test fragility: replace exact float equality with tolerance
comparisons to handle GCC LTO inlining divergence across translation units.

132 -> 141 SQL objects. 22 -> 24 regression suites. All 24 passing.
2026-02-25 13:53:22 -07:00

52 lines
2.4 KiB
SQL

-- v013_features.sql -- Tests for v0.13.0: make_equatorial constructor
--
-- Verifies that make_equatorial() produces the same result as text
-- literal casting, validates input bounds, and round-trips correctly.
-- Load the extension
CREATE EXTENSION IF NOT EXISTS pg_orrery;
-- ============================================================
-- make_equatorial() constructor
-- ============================================================
-- Basic construction and accessor round-trip
SELECT eq_ra(make_equatorial(6.75, 45.0, 1000.0)) AS ra_hours;
SELECT eq_dec(make_equatorial(6.75, 45.0, 1000.0)) AS dec_deg;
SELECT eq_distance(make_equatorial(6.75, 45.0, 1000.0)) AS dist_km;
-- Compare with text literal cast (must match)
SELECT make_equatorial(6.75, 45.0, 1000.0)::text = '(6.75000000,45.00000000,1000.000)'::equatorial::text
AS constructor_matches_literal;
-- Edge cases: RA boundaries
SELECT make_equatorial(0.0, 0.0, 0.0) IS NOT NULL AS ra_zero;
SELECT make_equatorial(23.99999999, 0.0, 0.0) IS NOT NULL AS ra_max;
-- Edge cases: Dec boundaries
SELECT make_equatorial(12.0, -90.0, 0.0) IS NOT NULL AS dec_south_pole;
SELECT make_equatorial(12.0, 90.0, 0.0) IS NOT NULL AS dec_north_pole;
-- Edge cases: zero distance (stars)
SELECT eq_distance(make_equatorial(12.0, 45.0, 0.0)) AS zero_distance;
-- Negative distance (allowed -- could represent parallax distance in km)
SELECT eq_distance(make_equatorial(12.0, 45.0, -1000.0)) AS negative_distance;
-- ============================================================
-- Error cases
-- ============================================================
-- RA out of range (must fail)
\set ON_ERROR_ROLLBACK on
DO $$ BEGIN PERFORM make_equatorial(24.0, 0.0, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'ra=24: %', SQLERRM; END $$;
DO $$ BEGIN PERFORM make_equatorial(-0.1, 0.0, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'ra=-0.1: %', SQLERRM; END $$;
-- Dec out of range (must fail)
DO $$ BEGIN PERFORM make_equatorial(12.0, 90.1, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'dec=90.1: %', SQLERRM; END $$;
DO $$ BEGIN PERFORM make_equatorial(12.0, -90.1, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'dec=-90.1: %', SQLERRM; END $$;
-- NaN and Inf (must fail)
DO $$ BEGIN PERFORM make_equatorial('NaN'::float8, 0.0, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'ra=NaN: %', SQLERRM; END $$;
DO $$ BEGIN PERFORM make_equatorial(12.0, 'Infinity'::float8, 0.0); EXCEPTION WHEN OTHERS THEN RAISE NOTICE 'dec=Inf: %', SQLERRM; END $$;