From eeee6ced22fb7bd56d14889b560deec7e4cf73ed Mon Sep 17 00:00:00 2001 From: Daniel McCoy Stephenson Date: Sun, 15 Nov 2026 20:27:57 -0700 Subject: [PATCH] Test body kind names and the ring catalogue kindName and SolarSystem::rings() were the only public orrery_core functions no test referenced. test_ephemeris now checks the word each BodyKind is shown as (the HUD and the USD layer's `kind`), the kinds of real catalogue bodies, and the six rings against tools/bodies.py's committed NSSDCA radii: order, owning planet, inside/outside radius, outside the planet's sphere, and colour and opacity in range. Co-Authored-By: Claude Opus 5.5 --- README.md | 2 +- tests/test_ephemeris.cpp | 54 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb1a2c4..444c3e2 100644 --- a/README.md +++ b/README.md @@ -309,7 +309,7 @@ For scale: The other tests: -- `test_ephemeris` also checks the catalogue's queries on the fetched data: finding a body by any case or by part of its name, the date range a day inside DE440s's coverage with the system evaluating at both ends, osculating orbits (none for the Sun or a spacecraft; Earth's and the Moon's from their DE states; a table body's from its table), poles (unit vectors, none for spacecraft, comets or Eris; Earth's 23.44° from ecliptic north at J2000) and the axial tilt the HUD prints (Earth 23.44°, and Venus 177.36° and Uranus 97.77° from their IAU poles reversed, since they turn backwards; none for Eris or a spacecraft), and body frames whose +Z is the pole and whose prime meridian comes back after one sidereal day. +- `test_ephemeris` also checks the catalogue's queries on the fetched data: finding a body by any case or by part of its name, the date range a day inside DE440s's coverage with the system evaluating at both ends, osculating orbits (none for the Sun or a spacecraft; Earth's and the Moon's from their DE states; a table body's from its table), poles (unit vectors, none for spacecraft, comets or Eris; Earth's 23.44° from ecliptic north at J2000) and the axial tilt the HUD prints (Earth 23.44°, and Venus 177.36° and Uranus 97.77° from their IAU poles reversed, since they turn backwards; none for Eris or a spacecraft), body frames whose +Z is the pole and whose prime meridian comes back after one sidereal day, the word each body kind is shown as (the HUD and the USD layer's `kind`), and the six rings at their catalogued radii, each outside its planet. - `test_kepler` covers Kepler's equation (elliptic and hyperbolic) to 1e-12, circular and eccentric orbits (by mean and by eccentric anomaly), the state ↔ elements round trip, and table interpolation that is exact against a synthetic Phobos-like orbit. - `test_element_table` covers the moon and dwarf-planet element tables: loading a catalogue CSV by column name and sorting it by epoch, the error for a table with no rows, linear a, e and i between samples, node and argument of periapsis taking the shorter arc across 0/360, the mean longitude unwrapped by the whole turns the first sample predicts, and two-body propagation (flagged as extrapolated) before the first sample, after the last and around a single sample. - `test_time` covers Julian Dates (including the Gregorian start and the proleptic days before it), calendar dates rounding to the millisecond, every leap-second step on its date and with its value, UTC to TDB and back on both sides of each step, ISO parsing (the accepted forms, and rejecting impossible dates, trailing text, fields not written as their fixed width in digits, and seconds that are not a plain decimal number), date formatting and the system clock. diff --git a/tests/test_ephemeris.cpp b/tests/test_ephemeris.cpp index 83d23ed..d412bf7 100644 --- a/tests/test_ephemeris.cpp +++ b/tests/test_ephemeris.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "check.hpp" #include "orrery/csv.hpp" @@ -221,5 +222,58 @@ int main() { CHECK(dot(f.x, later.x) > 1 - 1e-9); CHECK(dot(f.x, half.x) < -1 + 1e-6); } + + SECTION("body kinds and rings: the names the HUD and the USD layer print, and the ring catalogue"); + { + // kindName is what the HUD shows after a body's name and what the USD + // layer writes as its `kind`, so every kind has its own word. + CHECK(std::string(kindName(BodyKind::Star)) == "star"); + CHECK(std::string(kindName(BodyKind::Planet)) == "planet"); + CHECK(std::string(kindName(BodyKind::Dwarf)) == "dwarf planet"); + CHECK(std::string(kindName(BodyKind::Moon)) == "moon"); + CHECK(std::string(kindName(BodyKind::Comet)) == "comet"); + CHECK(std::string(kindName(BodyKind::Spacecraft)) == "spacecraft"); + auto kindOf = [&](const char* name) { + const int i = body(name); + return i < 0 ? std::string("absent") : std::string(kindName(sys.bodies()[static_cast(i)].kind)); + }; + CHECK(kindOf("Sun") == "star"); + CHECK(kindOf("Earth") == "planet"); + CHECK(kindOf("Pluto") == "dwarf planet"); + CHECK(kindOf("Ceres") == "dwarf planet"); + CHECK(kindOf("Moon") == "moon"); + CHECK(kindOf("Charon") == "moon"); + CHECK(kindOf("Halley") == "comet"); + CHECK(kindOf("Voyager 1") == "spacecraft"); + + // The rings are tools/bodies.py's NSSDCA radii (committed constants, + // not fetched data), in its order: Saturn's D, C, B, A and F rings, + // then Uranus's epsilon ring. Each belongs to its planet, lies outside + // the planet's drawn sphere, and has a display colour and opacity in + // range. + struct Expected { + const char* planet; + const char* name; + double innerKm, outerKm; + }; + const Expected expected[] = { + {"Saturn", "D ring", 66900, 74510}, {"Saturn", "C ring", 74658, 91975}, + {"Saturn", "B ring", 91975, 117507}, {"Saturn", "A ring", 122340, 136780}, + {"Saturn", "F ring", 139801, 139851}, {"Uranus", "epsilon ring", 51119, 51179}, + }; + const std::vector& rings = sys.rings(); + CHECK(rings.size() == sizeof expected / sizeof expected[0]); + for (size_t k = 0; k < rings.size() && k < sizeof expected / sizeof expected[0]; ++k) { + const Ring& ring = rings[k]; + const Expected& e = expected[k]; + CHECK_MSG(ring.name == e.name, ring.name); + CHECK_MSG(ring.planet == body(e.planet), ring.name); + CHECK_MSG(ring.innerKm == e.innerKm && ring.outerKm == e.outerKm, ring.name); + CHECK_MSG(ring.planet >= 0 && ring.innerKm > sys.bodies()[static_cast(ring.planet)].radiusKm, + ring.name); + for (float c : ring.color) CHECK_MSG(c >= 0 && c <= 1, ring.name); + CHECK_MSG(ring.alpha > 0 && ring.alpha <= 1, ring.name); + } + } return check::finish(); }