← All notes

Testing training maths against its own definitions

FitnessTracker has 800 tests. The useful ones do not check outputs I computed by hand — they check identities the formulas promise.

FitnessTracker is my personal training database for iOS and macOS. It imports workouts from a watch, syncs Strava and intervals.icu, and computes the numbers endurance athletes use: training stress, fitness and fatigue curves, normalized power, race predictions.

Formulas like these are easy to get subtly wrong and hard to notice, because the output is always a plausible-looking number. A test that says "this ride should score 87.3" only proves the code agrees with whatever I calculated by hand — possibly with the same mistake.

Test the promise, not the number

Most of these metrics come with identities built into their definitions. One hour at your threshold power is, by definition, a training stress score of exactly 100. Stress grows with the square of intensity. If you train at the same daily load forever, your fitness curve converges on that load. Those statements are true regardless of any particular workout, so they make good tests:

// One hour exactly at FTP should be IF 1.0 and TSS ~100 by definition.
XCTAssertEqual(try XCTUnwrap(summary.trainingStressScore), 100, accuracy: 3)

A bug in the formula almost always breaks an identity like that, and the test explains itself when it fails.

Round trips and regressions

The other big group is round trips: encode a workout as a FIT file, decode it, and check that nothing changed. Export a route as GPX and parse it back. If both directions are mine, the pair has to agree with itself.

And after an audit in September 2026, every bug that turned up got exactly one regression test in its own file, named for what broke. The file reads like a history of the app's mistakes, and none of them has come back.

One thing the tests deliberately do not claim: the screen-render tests prove a view draws without crashing, not that it shows the right content, because on macOS the renderer returns a blank image for navigation stacks either way. Writing down what a test does not prove turned out to be as useful as the test.