Browse Source

docs: resolve 5 contradictions in continue.md

test-refactor
cinnaboot 2 months ago
parent
commit
372ae31658
  1. 14
      continue.md

14
continue.md

@ -5,7 +5,7 @@
### 1. Structure
- One `SCENARIO("description")` per logical test group, with `[tag1][tag2]` annotations
- Shared fixture: all constants, structs, and variables declared between `SCENARIO` opening and first `SECTION`
- Precompute expected values analytically at fixture level (use `scripts/*.py` for complex simulations)
- Run `scripts/precalc_*.py` to generate expected values — these Python scripts are the authoritative source, providing an independent check against the C++ simulation. Embed the values directly in `WithinAbs()` calls (no need to declare named constants unless the value is reused).
### 2. Duplication Elimination
- Use lambdas that capture the fixture for repeated setup→call→assert patterns
@ -13,14 +13,18 @@
- Single-line `SECTION`s when body is one statement: `SECTION("name") { helper(arg); }`
### 3. Assertions
- Include `src/test_utilities.h` for tolerance constants and test utilities
- `#include <catch2/matchers/catch_matchers_floating_point.hpp>` (required for `WithinAbs` matcher)
- `using Catch::Matchers::WithinAbs;` after includes
- `REQUIRE_THAT(value, WithinAbs(expected, tolerance))` — never `Approx()`
- **Always use named tolerance constants** — never hardcode raw numbers for tolerance in `WithinAbs()`.
#### Tolerance Reference
All constants defined in `src/test_utilities.h` — use those, do not redefine locally.
| Constant | Value | Use for |
|----------|-------|---------|
| `A_TOL` | `1e-6` | Semi-major axis (meters), magnitude < 1e10 (use `A_TOL_LARGE` for larger) |
| `A_TOL` | `1e-6` | Semi-major axis (meters), magnitude < 1e10 |
| `E_TOL` | `1e-12` | Eccentricity, round-trip conversion |
| `ANG_TOL` | `1e-12` | Angles in radians (nu, inc, Ω, ω) |
| `ANG_TOL_COARSE` | `1e-4` | Angles, degenerate cases (polar/retrograde) |
@ -30,7 +34,7 @@
| `REL_TOL` | `1e-8` | Relative / percentage errors (dimensionless) |
| `DRIFT_TOL` | `1e-12` | Energy drift percent (parabolic orbit) |
- Declare tolerance constants in the fixture (between `SCENARIO` opening and first `SECTION`)
- Tighten aggressively: if observed error is `1e-8`, use `1e-6` (two orders of margin)
- Replace qualitative checks (`a > b`) with quantitative (`WithinAbs(expected, tol)`)
- `INFO("label: " << value)` for debugging context
@ -42,14 +46,14 @@
- C++ tests typically use local coordinates (e.g., `vec3_distance(craft->local_position, (Vec3){0,0,0})`).
- Global distances are dominated by parent body positions (e.g., Earth-Sun distance swamps LEO orbit).
- **Always output SI units** (meters, m/s, seconds) — C++ tests use SI internally.
- Output C++-style comments with precalculated constants for embedding in the test.
- Output C++-style comments with precalculated expected values for embedding in the test. Tolerances are chosen separately by the test writer using the Tolerance Reference table — the precalc script should not output tolerance values.
- Run with: `python3 scripts/precalc_<test_name>.py`
- If sim_engine.py lacks a feature, use analytical formulas instead (**but notify the user what feature was missing**)
## Refactoring Procedure
### Step 1: Refactor
- Verify the test file has a TOML config in `old_tests/`. If it doesn't, skip — it's likely hardcoded.
- Verify the test file has a TOML config in `old_tests/`. If it doesn't, skip the TOML rewrite step — the test is likely hardcoded.
- Check if the test is already in `tests/` (already refactored). Skip if so.
- Check the capability matrix in Section 5 — if the test needs SOI, maneuvers, rendezvous, etc., flag this before starting.
- Process **one test file at a time**.

Loading…
Cancel
Save