diff --git a/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs b/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs index ad9aaa2d1..e92de5a72 100644 --- a/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs +++ b/tests/Aetheria.Shared.Tests/FireAuthorityTests.cs @@ -375,6 +375,11 @@ public sealed class FireAuthorityTests : IDisposable // tracking needed -- makes the mutation observable even with no jink at all: the mutant // mispredicts the intercept by Velocity * CommitHorizon, which the post-commit-jink assertion // below (expected to still hit) catches as a spurious miss. + // Cut 11: advance the zone clock before firing. Build leaves it at 0, so every shot fired with + // FireTime = 0 -- and `now - FireTime` equals `now + FireTime` when FireTime is 0. That is why the + // moving target Cut 5 added still left this test's own declared mutation (measure elapsed wrongly) + // alive: Stryker found `now + shot.FireTime` surviving. + e.Zone.Update(2.5f); e.Target.Velocity = float2(4, 0); FireControl.Fire(e.Weapon, e.WeaponItem, e.Shooter); var t = 0f; diff --git a/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs index 7213f2f4b..a4d9172fc 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut11Tests.cs @@ -34,7 +34,7 @@ public sealed class FireControlCut11Tests : IDisposable Directory.Delete(_root, true); } - private static GameplaySettings TestSettings() => new GameplaySettings + private static GameplaySettings TestSettings(float schematicCellSize = 1f) => new GameplaySettings { DefaultEntitySettings = new EntitySettings(), Tiers = new[] { new RarityTier { Name = "Common", Quality = .5f, Rarity = 0, Color = new float3(1, 1, 1) } }, @@ -44,7 +44,7 @@ public sealed class FireControlCut11Tests : IDisposable TargetGearInfoThreshold = .8f, FiringArc = 170, CommitHorizon = .5f, - SchematicCellSize = 1f, + SchematicCellSize = schematicCellSize, UnaidedAccuracy = .05f, UnaidedTracking = 10f, UnaidedPrecision = 2f, @@ -79,7 +79,7 @@ public sealed class FireControlCut11Tests : IDisposable string zoneName = "Cut11", float damage = 5, float velocity = 0, float accuracy = 1, bool equipShield = false, float shieldCapacity = 30, - bool markers = false) + bool markers = false, float spread = 0, float schematicCellSize = 1f) { // 5 wide x 3 tall: schematic x runs port (0) to starboard (4). Tool gear may only occupy interior // cells, which on this hull is the middle row x = 1..3, so the markers sit at (1, 1) and (3, 1) -- @@ -101,7 +101,7 @@ public sealed class FireControlCut11Tests : IDisposable Behaviors = { new InstantWeaponData { Damage = Constant(damage), Range = Constant(1000), MinRange = Constant(0), - Velocity = Constant(velocity), Spread = Constant(0), DamageSpread = Constant(0), + Velocity = Constant(velocity), Spread = Constant(spread), DamageSpread = Constant(0), Penetration = Constant(0), Count = Constant(1), BurstTime = Constant(0), Cooldown = Constant(1000), DamageCurve = new BezierCurve { Keys = new[] { float4(0, 1, 0, 0), float4(1, 1, 0, 0) } } } } @@ -136,7 +136,7 @@ public sealed class FireControlCut11Tests : IDisposable var ledger = new ProvenanceLedger(); for (var i = 1; i <= 16; i++) ledger.Lots[i] = new Lot { Origin = new Attributed(), Quality = 1 }; - var items = new ItemManager(cache, ledger, TestSettings(), _ => { }); + var items = new ItemManager(cache, ledger, TestSettings(schematicCellSize), _ => { }); var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = zoneName, Owner = null }, null); EquippableItem Make(string name, int lot, float durability) => new EquippableItem @@ -317,6 +317,32 @@ public sealed class FireControlCut11Tests : IDisposable } } + // ---- pSpread is the share of the spread cone the target's silhouette covers. ---- + + // Every earlier fixture used zero spread (pSpread is then 1 regardless) and a cell size of exactly 1 (so + // multiplying and dividing by it agree), which left the whole spread term untested. This pins what the + // number MEANS rather than how it is computed: a silhouette that exactly fills the cone scores 1, one half + // the cone's angular size scores .5, and one bigger than the cone saturates at 1. Here the 5-wide hull at a + // cell size of 2 has a half-extent of 5 world units, against a 10-degree cone (5-degree half-angle). + [Fact] + public void PSpreadIsTheSilhouettesShareOfTheSpreadCone() + { + const float halfExtent = 5f, halfCone = 5f; + float At(float range) + { + var e = Build(spread: 2 * halfCone, schematicCellSize: 2f); + e.Target.Position = e.Shooter.Position + float3(0, 0, range); + return FireControl.Inspect(e.Weapon, e.Shooter, e.Target).PSpread; + } + + var fills = halfExtent / (float) Math.Tan(halfCone * Math.PI / 180); // silhouette == cone + var half = halfExtent / (float) Math.Tan(halfCone / 2 * Math.PI / 180); // silhouette == half the cone + Assert.Equal(1f, At(fills), 2); + Assert.Equal(.5f, At(half), 2); + Assert.Equal(1f, At(fills / 3), 2); // bigger than the cone: saturates, never exceeds 1 + Assert.True(At(half * 2) < At(half)); // and falls away with range + } + // ---- Zones roll differently. ---- // The roll is a function of (zone, shot id). Replacing `CombatSeed *` with `/` in Commit's seed drops the diff --git a/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs b/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs index 06909df68..acdeeb48d 100644 --- a/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs +++ b/tests/Aetheria.Shared.Tests/FireControlCut9Tests.cs @@ -285,7 +285,10 @@ public sealed class FireControlCut9Tests : IDisposable MinimumTemperature = -1000, MaximumTemperature = 1000, OptimalTemperature = 0, PlateauWidth = 2000, Behaviors = { new TargetingSystemData { - Accuracy = Constant(1f), Resolution = Constant(1000f), Precision = Constant(precision), Tracking = Constant(100000f) + // Cut 11: a finite Resolution, so pSensor actually varies with info. At 1000 it saturated to exactly 1 + // for any info above the detection threshold, which made `x * pSensor` and `x / pSensor` the same + // number and let a mutant of Inspect's product survive HitProbabilityMatchesInspect. + Accuracy = Constant(1f), Resolution = Constant(2f), Precision = Constant(precision), Tracking = Constant(100000f) } } }); cache.FlushAsync().Wait(); @@ -418,6 +421,17 @@ public sealed class FireControlCut9Tests : IDisposable Check("behind the mount"); e.Target.Position = float3(0, 0, 100); + // Cut 11: a shooter far from the origin. Every other configuration keeps the shooter at float3.zero, + // where `target - source` and `target + source` are the same vector; here the correct separation is + // 500 (in range) while the mutated sum is 1300 (out of range), so a sign mutant in either caller's + // bearing makes the two disagree. + var home = e.Shooter.Position; + e.Shooter.Position = float3(600, 0, 0); + e.Target.Position = float3(600, 0, 500); + Check("shooter far from the origin"); + e.Shooter.Position = home; + e.Target.Position = float3(0, 0, 100); + e.Shooter.VisibleEntities.Remove(e.Target); Check("not visible"); @@ -425,7 +439,7 @@ public sealed class FireControlCut9Tests : IDisposable var nullHud = FireControl.Inspect(e.Weapon, e.Shooter, null).PBase; Assert.True(nullHot == nullHud, $"no target: {nullHot} != {nullHud}"); } - Assert.Equal(21, checkedConfigurations); // 3 precisions x (4 info levels + out of range + behind + not visible) + Assert.Equal(24, checkedConfigurations); // 3 precisions x (4 info levels + out of range + behind + far shooter + not visible) } // The cost regression itself. A target out of range is the common case for every AI and turret, and it