From 66641b46defa157cf1a2b9750a303fbdf27a9733 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 10 Oct 2026 19:47:53 +0200 Subject: [PATCH] ThrustAllocatorTests: throttles stay in bounds and floors hold wherever the solve ends Co-Authored-By: Claude Opus 5.5 --- .../ThrustAllocatorTests.cs | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs b/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs index 405bb8833..7e36f5569 100644 --- a/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs +++ b/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs @@ -447,6 +447,34 @@ public class ThrustAllocatorTests } } + [Fact] + public void TheThrottlesStayInBoundsWhateverTheSolveEnds() + { + // The solver can stop at its iteration limit rather than converge. Probed on 64000 calls over 1 to 32 columns, scales + // 1e-6 to 1e6, micro and ordinary intents (2026-10-10): 8 of 60297 solves reached it, all on 32 synthetic columns, all with + // intents near 1e-8, none from a fresh allocator, none on a shipped hull (the largest has 8 thrusters). Wherever the + // solve ends, the allocator hands back what it has: finite, within [0,1], and the floored columns at full. + var rng = new System.Random(20261010); + float Rand(float lo, float hi) => lo + (float) rng.NextDouble() * (hi - lo); + foreach (var scale in new[] { 1e-3f, 1f }) + for (var round = 0; round < 12; round++) + { + var hull = Enumerable.Range(0, 32).Select(_ => new float3(Rand(-1, 1) * scale, Rand(-1, 1) * scale, rng.Next(4) == 0 ? 0 : Rand(-.3f, .3f) * scale)).ToArray(); + var allocator = new ThrustAllocator(); + var throttle = new float[hull.Length]; + for (var call = 0; call < 40; call++) + { + var micro = rng.Next(4) == 0 ? 1e-7f : 1f; + var floor = rng.Next(3) == 0; + allocator.Allocate(hull, new float2(Rand(-1, 1) * micro, Rand(-1, 1) * micro), Rand(-1.5f, 1.5f) * micro, throttle, floor); + Assert.All(throttle, t => Assert.InRange(t, 0f, 1f)); + if (floor) + for (var i = 0; i < hull.Length; i++) + if (hull[i].y > 0) Assert.Equal(1f, throttle[i]); + } + } + } + [Fact] public void AMicroIntentIsServed() {