From 6d8195811df35a698dc0ae19c1f6cd0f603577ef Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 24 Sep 2026 19:38:30 +0200 Subject: [PATCH] Fix a tolerance-overload bug that made intercept precision asserts inert `Precision` was declared `const float`, so `Assert.Equal(a, b, Precision)` bound to xunit's absolute-tolerance overload (allowing any two values within 4.0 of each other) instead of the intended 4-decimal-place overload. Hand-mutating the `t2 > 0 ? min(t1, t2) : t1` ternary to always return `t1` (math.cs:287) exposed it: the assertion silently accepted a result almost 0.27 away from the expected value. Declaring it `const int` selects the correct overload; confirmed the same hand mutation now fails. Also add the float2-overload euler-integration length-validation test the mutation report showed missing (BatchMath.cs:208's ValidateEqualLengths call had no test at all). Co-Authored-By: Claude Opus 5.5 --- .../cultmath/tests/CultMath.Tests/BatchMathTests.cs | 12 ++++++++++++ .../tests/CultMath.Tests/FirstOrderInterceptTests.cs | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/packages/cultmath/tests/CultMath.Tests/BatchMathTests.cs b/packages/cultmath/tests/CultMath.Tests/BatchMathTests.cs index c5196154..3db3259c 100644 --- a/packages/cultmath/tests/CultMath.Tests/BatchMathTests.cs +++ b/packages/cultmath/tests/CultMath.Tests/BatchMathTests.cs @@ -338,6 +338,18 @@ public sealed class BatchMathTests BatchMath.IntegrateSemiImplicitEuler2D(0.0f, dynamicMask, position, velocity, acceleration)); } + [Fact] + public void Float2EulerIntegrationValidatesEqualSpanLengths() + { + var dynamicMask = new float[3]; + var position = new float2[3]; + var velocity = new float2[2]; + var acceleration = new float2[3]; + + Assert.Throws(() => + BatchMath.IntegrateSemiImplicitEuler2D(0.5f, dynamicMask, position, velocity, acceleration)); + } + [Fact] public void Float2RadialFalloffValidatesEqualSpanLengths() { diff --git a/packages/cultmath/tests/CultMath.Tests/FirstOrderInterceptTests.cs b/packages/cultmath/tests/CultMath.Tests/FirstOrderInterceptTests.cs index 91591645..a211d266 100644 --- a/packages/cultmath/tests/CultMath.Tests/FirstOrderInterceptTests.cs +++ b/packages/cultmath/tests/CultMath.Tests/FirstOrderInterceptTests.cs @@ -24,7 +24,7 @@ namespace CultMath.Tests; // determinant > 0 with both roots <= 0 => 0 (via max(t2, 0)). public sealed class FirstOrderInterceptTests { - private const float Precision = 4; + private const int Precision = 4; [Fact] public void ZeroRelativeVelocityReturnsZeroTime()