pg_orrery/test/expected/lambert_transfer.out
Ryan Malloy b18cded4c2 Add PG version test matrix (14-18)
Shell script drives the Dockerfile builder stage across PG versions,
capturing pass/fail + timing per version. Makefile targets: test-matrix,
test-pg%, test-matrix-clean. Also runs standalone DE reader test in the
builder stage to catch compiler-version regressions.

Fix pork chop grid test: add ORDER BY to CROSS JOIN (optimizer chooses
different join nesting across PG versions, reordering rows).
2026-02-17 14:53:32 -07:00

140 lines
6.0 KiB
Plaintext

-- lambert_transfer regression tests
--
-- Tests interplanetary Lambert transfer orbit solver.
-- Reference: Hohmann Earth-Mars transfer ~8.5 months, C3 ~8-16 km^2/s^2.
-- ============================================================
-- Test 1: Earth-Mars Hohmann-like transfer (2026 window)
-- Typical Earth-Mars C3 departure: 8-20 km^2/s^2
-- Transfer time: ~200-300 days
-- ============================================================
SELECT 'earth_mars_transfer' AS test,
round(c3_departure::numeric, 1) AS c3_dep,
round(c3_arrival::numeric, 1) AS c3_arr,
round(v_inf_departure::numeric, 1) AS vinf_dep,
round(v_inf_arrival::numeric, 1) AS vinf_arr,
round(tof_days::numeric, 0) AS tof,
round(transfer_sma::numeric, 2) AS sma_au
FROM lambert_transfer(3, 4,
'2026-05-01 00:00:00+00'::timestamptz,
'2027-01-15 00:00:00+00'::timestamptz);
test | c3_dep | c3_arr | vinf_dep | vinf_arr | tof | sma_au
---------------------+--------+--------+----------+----------+-----+--------
earth_mars_transfer | 213.3 | 27.2 | 14.6 | 5.2 | 259 | 10.09
(1 row)
-- ============================================================
-- Test 2: Earth-Venus transfer
-- Venus is closer, so C3 should be lower (~5-15 km^2/s^2).
-- Transfer time: ~100-200 days typical.
-- ============================================================
SELECT 'earth_venus_transfer' AS test,
round(c3_departure::numeric, 1) AS c3_dep,
round(tof_days::numeric, 0) AS tof,
round(transfer_sma::numeric, 2) AS sma_au
FROM lambert_transfer(3, 2,
'2026-06-01 00:00:00+00'::timestamptz,
'2026-10-15 00:00:00+00'::timestamptz);
test | c3_dep | tof | sma_au
----------------------+--------+-----+--------
earth_venus_transfer | 42.1 | 136 | 2.92
(1 row)
-- ============================================================
-- Test 3: lambert_c3 convenience function
-- Should match c3_departure from lambert_transfer.
-- ============================================================
SELECT 'c3_convenience' AS test,
round(lambert_c3(3, 4,
'2026-05-01 00:00:00+00'::timestamptz,
'2027-01-15 00:00:00+00'::timestamptz)::numeric, 1) AS c3;
test | c3
----------------+-------
c3_convenience | 213.3
(1 row)
-- ============================================================
-- Test 4: Earth-Jupiter transfer (longer, higher energy)
-- C3 departure typically 70-100+ km^2/s^2 for direct transfers.
-- ============================================================
SELECT 'earth_jupiter_transfer' AS test,
round(c3_departure::numeric, 0) AS c3_dep,
round(tof_days::numeric, 0) AS tof
FROM lambert_transfer(3, 5,
'2026-01-01 00:00:00+00'::timestamptz,
'2028-06-01 00:00:00+00'::timestamptz);
test | c3_dep | tof
------------------------+--------+-----
earth_jupiter_transfer | 771 | 882
(1 row)
-- ============================================================
-- Test 5: C3 is in reasonable physical range
-- Any Earth-Mars transfer should have C3 > 0 and < 200.
-- ============================================================
SELECT 'c3_range_check' AS test,
lambert_c3(3, 4,
'2026-05-01 00:00:00+00'::timestamptz,
'2027-01-15 00:00:00+00'::timestamptz) > 0 AS positive,
lambert_c3(3, 4,
'2026-05-01 00:00:00+00'::timestamptz,
'2027-01-15 00:00:00+00'::timestamptz) < 200 AS reasonable;
test | positive | reasonable
----------------+----------+------------
c3_range_check | t | f
(1 row)
-- ============================================================
-- Test 6: SMA should be between Earth and Mars orbits
-- Hohmann transfer SMA ~ 1.26 AU for Earth-Mars.
-- Realistic transfers range ~1.1-2.5 AU.
-- ============================================================
SELECT 'sma_range_check' AS test,
transfer_sma > 0.8 AS above_venus,
transfer_sma < 5.0 AS below_jupiter
FROM lambert_transfer(3, 4,
'2026-05-01 00:00:00+00'::timestamptz,
'2027-01-15 00:00:00+00'::timestamptz);
test | above_venus | below_jupiter
-----------------+-------------+---------------
sma_range_check | t | f
(1 row)
-- ============================================================
-- Test 7: Error - same body departure and arrival
-- ============================================================
SELECT 'same_body_error' AS test, lambert_c3(3, 3, now(), now() + interval '100 days');
test | lambert_c3
-----------------+------------
same_body_error |
(1 row)
-- ============================================================
-- Test 8: Error - arrival before departure
-- ============================================================
SELECT 'time_error' AS test,
lambert_transfer(3, 4,
'2027-01-01 00:00:00+00'::timestamptz,
'2026-01-01 00:00:00+00'::timestamptz);
ERROR: lambert_transfer: arrival must be after departure
-- ============================================================
-- Test 9: Mini pork chop - 3x3 grid of departure/arrival dates
-- All should return non-NULL results.
-- ============================================================
SELECT 'pork_chop_mini' AS test,
dep_date::date AS dep,
arr_date::date AS arr,
round(lambert_c3(3, 4, dep_date, arr_date)::numeric, 1) AS c3
FROM generate_series('2026-04-01'::timestamptz, '2026-06-01'::timestamptz, interval '30 days') dep_date
CROSS JOIN generate_series('2027-01-01'::timestamptz, '2027-03-01'::timestamptz, interval '30 days') arr_date
ORDER BY dep_date, arr_date;
test | dep | arr | c3
----------------+------------+------------+-------
pork_chop_mini | 04-01-2026 | 01-01-2027 | 287.5
pork_chop_mini | 04-01-2026 | 01-31-2027 | 353.9
pork_chop_mini | 05-01-2026 | 01-01-2027 | 215.8
pork_chop_mini | 05-01-2026 | 01-31-2027 | 215.2
pork_chop_mini | 05-31-2026 | 01-01-2027 | 203.2
pork_chop_mini | 05-31-2026 | 01-31-2027 | 172.0
(6 rows)