using NUnit.Framework; using ProjectM.Simulation; using Unity.Mathematics; namespace ProjectM.Tests { /// /// MC-2 pure-math tests for the new EnemyAIMath helpers: BandVelocity (Spitter range-band keep-distance) and /// ClusterOffset (swarmer pack placement). No ECS world. /// public class EnemyAIMathMC2Tests { [Test] public void BandVelocity_AdvancesWhenTooFar() { var v = EnemyAIMath.BandVelocity(new float3(0, 1, 0), new float3(20, 1, 0), 5f, 9f, 1.5f); Assert.Greater(v.x, 0.1f, "too far -> moves toward the target"); Assert.AreEqual(0f, v.y, 1e-5f, "planar"); } [Test] public void BandVelocity_RetreatsWhenTooClose() { var v = EnemyAIMath.BandVelocity(new float3(0, 1, 0), new float3(3, 1, 0), 5f, 9f, 1.5f); Assert.Less(v.x, -0.1f, "too close -> backs away from the target"); } [Test] public void BandVelocity_HoldsInBand() { var v = EnemyAIMath.BandVelocity(new float3(0, 1, 0), new float3(9, 1, 0), 5f, 9f, 1.5f); Assert.AreEqual(0f, math.length(v), 1e-4f, "inside the dead-zone band -> hold and fire"); } [Test] public void ClusterOffset_SingleAtCentre_PackSpread() { var c = new float3(100, 1, 5); var single = EnemyAIMath.ClusterOffset(c, 0, 1, 2.5f); Assert.AreEqual(c.x, single.x, 1e-5f, "a lone swarmer spawns at the pack centre"); Assert.AreEqual(c.z, single.z, 1e-5f); var a = EnemyAIMath.ClusterOffset(c, 0, 4, 2.5f); var b = EnemyAIMath.ClusterOffset(c, 1, 4, 2.5f); Assert.Greater(math.distance(a, b), 0.01f, "pack members get distinct offsets"); var again = EnemyAIMath.ClusterOffset(c, 2, 4, 2.5f); Assert.AreEqual(0f, math.distance(again, EnemyAIMath.ClusterOffset(c, 2, 4, 2.5f)), 1e-5f, "deterministic"); } } }