Compare floats tolerantly in round-trip test instead of ignoring them - #120
Merged
Conversation
The e2e round-trip test (and the near-identical helper in compare_test.go) skipped every float64 value, so numeric corruption round-tripped undetected. Replace the blanket float skip with cmpopts.EquateApprox(0, 1e-4). Only Date and EpochTime remain ignored (regenerated on every build). The 1e-4 absolute tolerance sits below the smallest smoothing precision (positions 3dp, scale 2dp, colors 5dp) so it absorbs rounding noise while catching real movement. For the tolerance to hold, the compared floats must be in their committed (smoothed) form. Two GHE_Dev fixtures still held raw TTS snap-point Positions and Rotations that never round-tripped identically; smooth those values in place (matching the tool's own output exactly) as 3_snap_points already is. Fixes #98 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
argonui
force-pushed
the
test/e2e-compare-numbers
branch
from
August 4, 2026 03:04
f871ebd to
614a0c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes #98The end-to-end round-trip test
tests/e2e_test.gotreated everyfloat64as unpredictable and skipped it entirely:That meant numeric corruption in the reverse→build round trip passed undetected — the very thing the round-trip property is supposed to guarantee.
Fix
Stop skipping floats. Compare them approximately with
cmpopts.EquateApprox(0, 1e-4). OnlyDateandEpochTimeremain ignored, since they are regenerated on every build by design.The near-identical
ignoreUnpredictablein rootcompare_test.gogot the same treatment (a sharedapproxFloatsoption applied to bothcmp.Diffcalls).Tolerance choice: 1e-4
Number smoothing (see
objects/AGENTS.md) rounds positions to 3 decimal places, scale to 2, and colors to 5. The coarsest of those, 3dp, means legitimate values differ by at most 5e-4 from an unrounded input. An absolute tolerance of1e-4sits comfortably below any real change a user could make in-game (nudging a card moves it far more than 1e-4) while staying above floating-point rounding noise. It is tight enough to catch real numeric corruption yet loose enough not to flag representation jitter.Fixture normalization
For a tolerance this tight to hold, the compared floats must be in their committed (smoothed) form — the form the tool always emits.
3_snap_points.jsonalready stores whole-degree rotations, but two fixtures (GHE_Dev_no_objects,GHE_Dev_no_objects_no_lua) still contained raw TTS snap-pointPosition/Rotationvalues (e.g.180.0298,-36.0014) that the tool smooths on every build and therefore never round-trip identically. Those snap-point values are smoothed in place, exactly matching the tool's own output (verified programmatically). No other fields changed. Rotations round to whole degrees, which is why raw snap-point rotations could not survive a tight tolerance untouched.Proof the test now catches corruption
Temporarily mutated
smoothPosinobjects/numbersmoother.gotoroundFloat(f, 3) * 2:go test ./tests/passed — corruption invisible.go test ./tests/FAILS. The fixtures carrying position data (3_snap_points,GHE_Dev_no_objects,GHE_Dev_no_objects_no_lua) report the doubled coordinates; position-free fixtures still pass.Reverting the mutation restores full green:
go test ./...,go build ./..., andgo vet ./...all pass.