Skip to content

Review the unit tests and fix the bugs they found - #193

Merged
ptgrogan merged 11 commits into
mainfrom
test-review
Dec 5, 2026
Merged

ptgrogan merged 11 commits into
mainfrom
test-review

Conversation

@ptgrogan

@ptgrogan ptgrogan commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Reviews the unit tests, removing trivial and redundant ones and tightening weak assertions, and fixes the bugs the review found.

Unit tests

  • Removes 480 of 2,884 tests: tests that restate the code (getters, defaults, pydantic bounds without a custom validator), tests without assertions, direction-only checks implied by reference values, copies of inherited base-class tests, and 69 per-fixture size checks of the catalog (now one test over every fixture, including the *_pixels.npz fixtures that were not checked). No test that was the only coverage of a function, argument, or branch was removed.
  • Runs test_rise_and_set_times_are_refined (in tests/schemas/orbit/test_gp.py), which was nested under the __main__ guard and never collected.
  • Tightens assertions that could not fail or checked only ranges, types, or counts, against values derived independently of the code: analytic geometry, skyfield and DE421, hand-derived Walker and train spacings, and brute-force Pareto fronts. Adds the missing check that instruments rolled on a yawed target attitude are mirrored.
  • The Optuna search test used NSGA-II, which on the test's conditional design space samples the same designs as random sampling, so it could not detect a broken search. It now uses the default sampler (TPE), checks that each trial is told its design's means in the objectives' directions, and that the search finds more of the true front than random sampling.

Fixes

  • mean_anomaly_to_true_anomaly and true_anomaly_to_mean_anomaly solve Kepler's equation (Newton's method) instead of a third-order series, which was inaccurate at high eccentricities: members of Molniya, Tundra, and Keplerian constellations (get_derived_orbit) were placed off their mean anomalies.
  • compute_j2_raan_rate, compute_j2_aop_rate, and compute_j2_mean_motion_rate scale J2 by the equatorial radius, to which it is normalized, instead of the mean radius. Molniya and Tundra periods (refined by SGP4) are unchanged.
  • get_copernicus_dem_tile_urls wraps tiles across the antimeridian, limits them to the tiles' latitudes, covers every longitude about a pole, and spans a spherical cap's longitudes exactly; compute_terrain_mask reads terrain across the antimeridian, and sample_dem_elevation wraps longitudes past 180.
  • tatc.visualization fills missing ends of periods in nanoseconds, removing a pandas 4 deprecation warning.

Documentation and validation notebooks

  • optimize_optuna documents that samplers relating decisions across trials (such as NSGA-II) sample conditional decisions at random.
  • ValidateLatencyNOAA20 caches its NOAA-20 element set in its own file; it shared data/orbits/weather.tle with ValidateOrbitGeneration, which then failed without the rest of the weather group.
  • ValidateOrbitGeneration shows geosynchronous orbits starting at their longitudes (fixed in 3.9.0; its table's longitudes at epoch are recomputed with the current code) and lists the earlier offset among the errors it found. The notebook was not rerun: its October 2026 element sets are no longer cached, and a rerun with current CelesTrak element sets changes results unrelated to this branch (on the same element sets, the Kepler fix changes only its Molniya apogee drift rates, within the range its text states).

Testing

The full suite passes, also with pandas 4 deprecation warnings as errors, and black --check is clean. The new tests of the fixes fail on the previous code.

Remove tests that restate the code (getters, defaults, declarative
pydantic bounds without custom validators), tests without assertions,
direction-only checks implied by reference values, and copies of
inherited behavior; merge the per-fixture size checks of the catalog
into one test over every fixture. Run test_rise_and_set_times_are_refined,
which was nested under the __main__ guard and never collected.
mean_anomaly_to_true_anomaly and true_anomaly_to_mean_anomaly solve
Kepler's equation (Newton's method) rather than approximate it with a
third-order series, which erred by about 11 deg at the eccentricity of
Molniya orbits and placed members of eccentric constellations off their
mean anomalies. The tests check Vallado's Example 2-1, the inversion of
the conversions at high eccentricities, and a Molniya member's position
a quarter period ahead of its lead.
Check expected values derived independently of the code under test
(analytic geometry, skyfield, hand-derived Walker spacings, brute-force
Pareto fronts) where tests checked only ranges, types, or counts, or
could not fail, and add the missing check of mirrored instruments under
a yawed target attitude.
compute_j2_raan_rate, compute_j2_aop_rate, and compute_j2_mean_motion_rate
scale J2 by the equatorial radius, to which it is normalized, rather than
the mean radius (about 0.22% too slow). The tests check Vallado's secular
mean anomaly rate and the sun-synchronous rate at Landsat's altitude.
get_copernicus_dem_tile_urls wraps tiles across the antimeridian, limits
them to the tiles' latitudes, covers every longitude about a pole, and
spans the exact longitudes of a spherical cap. compute_terrain_mask reads
terrain across the antimeridian and sample_dem_elevation wraps longitudes.
Add the J2, DEM, and pandas fixes to the change log.
On the test's conditional design space, NSGA-II samples the same designs as
random sampling (it relates only the decisions every trial makes), so the
test could not detect a broken optimizer. The test searches with the
default sampler (TPE), checks that each trial is told the means of its
design in the directions of the objectives, and that the search finds more
of the true front's hypervolume than random sampling of the same seed. The
docstring of optimize_optuna notes the limitation of such samplers.
…atencyNOAA20

ValidateLatencyNOAA20 and ValidateOrbitGeneration both cached TLEs as
data/orbits/weather.tle: the NOAA-20 element set of the latency notebook's
day made ValidateOrbitGeneration fail without the rest of the group.
…eir longitudes

The generated geosynchronous orbits start at the requested longitudes
since their node is solved for the longitude at the epoch; the table's
longitudes at epoch (computed with the current code, whose 30-day changes
are unchanged) and the text no longer show the offset of 0.013 deg of
earlier versions.
…validation notebooks

Trim the numbers from the fixed entries.
@ptgrogan
ptgrogan merged commit 81cff16 into main Dec 5, 2026
11 checks passed
@ptgrogan
ptgrogan deleted the test-review branch December 5, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant