| | 1 | | using NUnit.Framework; |
| | 2 | | using UnityEngine; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Linq; |
| | 5 | | using Configs; |
| | 6 | |
|
| | 7 | | public class IADSClusterCleanupTests : AgentTestBase { |
| | 8 | | private IADS _iads; |
| | 9 | |
|
| | 10 | | [SetUp] |
| 1 | 11 | | public override void Setup() { |
| 1 | 12 | | base.Setup(); |
| 1 | 13 | | _iads = new GameObject("IADS").AddComponent<IADS>(); |
| 1 | 14 | | _iads.Start(); |
| 1 | 15 | | } |
| | 16 | |
|
| | 17 | | [TearDown] |
| 1 | 18 | | public override void Teardown() { |
| 1 | 19 | | base.Teardown(); |
| 2 | 20 | | if (_iads != null) { |
| 1 | 21 | | GameObject.DestroyImmediate(_iads.gameObject); |
| 1 | 22 | | } |
| 1 | 23 | | } |
| | 24 | |
|
| 1 | 25 | | private AgentConfig CreateThreatConfig() => new AgentConfig { |
| | 26 | | ConfigFile = "brahmos.pbtxt", |
| | 27 | | AttackBehaviorConfigFile = "brahmos_direct_attack.pbtxt", |
| | 28 | | InitialState = new Simulation.State { |
| | 29 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 30 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 } |
| | 31 | | }, |
| | 32 | | StandardDeviation = new Simulation.State { |
| | 33 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 34 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 } |
| | 35 | | }, |
| | 36 | | DynamicConfig = new DynamicConfig { |
| | 37 | | SensorConfig = new Simulation.SensorConfig { |
| | 38 | | Type = Simulation.SensorType.Ideal, |
| | 39 | | Frequency = 10 |
| | 40 | | } |
| | 41 | | } |
| | 42 | | }; |
| | 43 | |
|
| 1 | 44 | | private AgentConfig CreateCarrierConfig() => new AgentConfig { |
| | 45 | | ConfigFile = "hydra70.pbtxt", |
| | 46 | | InitialState = new Simulation.State { |
| | 47 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 48 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 50 } |
| | 49 | | }, |
| | 50 | | StandardDeviation = new Simulation.State { |
| | 51 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 52 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 } |
| | 53 | | }, |
| | 54 | | DynamicConfig = new DynamicConfig { |
| | 55 | | SensorConfig = new Simulation.SensorConfig { |
| | 56 | | Type = Simulation.SensorType.Ideal, |
| | 57 | | Frequency = 10 |
| | 58 | | }, |
| | 59 | | FlightConfig = new FlightConfig { |
| | 60 | | ControllerType = ControllerType.ProportionalNavigation |
| | 61 | | } |
| | 62 | | } |
| | 63 | | }; |
| | 64 | |
|
| 0 | 65 | | private AgentConfig CreateMissileConfig() => new AgentConfig { |
| | 66 | | ConfigFile = "micromissile.pbtxt", |
| | 67 | | InitialState = new Simulation.State { |
| | 68 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 69 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 50 } |
| | 70 | | }, |
| | 71 | | StandardDeviation = new Simulation.State { |
| | 72 | | Position = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 }, |
| | 73 | | Velocity = new Simulation.CartesianCoordinates { X = 0, Y = 0, Z = 0 } |
| | 74 | | }, |
| | 75 | | DynamicConfig = new DynamicConfig { |
| | 76 | | SensorConfig = new Simulation.SensorConfig { |
| | 77 | | Type = Simulation.SensorType.Ideal, |
| | 78 | | Frequency = 10 |
| | 79 | | }, |
| | 80 | | FlightConfig = new FlightConfig { |
| | 81 | | ControllerType = ControllerType.ProportionalNavigation |
| | 82 | | } |
| | 83 | | } |
| | 84 | | }; |
| | 85 | |
|
| 1 | 86 | | private (Cluster, ThreatClusterData) MakeClusterWithThreats(params Threat[] threats) { |
| 1 | 87 | | var cluster = new Cluster(); |
| 6 | 88 | | foreach (var threat in threats) { |
| 1 | 89 | | cluster.AddObject(threat.gameObject); |
| 1 | 90 | | } |
| 1 | 91 | | var threatClusterData = new ThreatClusterData(cluster); |
| 1 | 92 | | var clusters = new List<Cluster> { cluster }; |
| 1 | 93 | | SetPrivateField(_iads, "_threatClusters", clusters); |
| 1 | 94 | | var map = new Dictionary<Cluster, ThreatClusterData> { [cluster] = threatClusterData }; |
| 1 | 95 | | SetPrivateField(_iads, "_threatClusterMap", map); |
| 1 | 96 | | return (cluster, threatClusterData); |
| 1 | 97 | | } |
| | 98 | |
|
| | 99 | | [Test] |
| 1 | 100 | | public void Carrier_Unassigned_WhenClusterFullyDestroyed() { |
| 1 | 101 | | var threat = CreateTestThreat(CreateThreatConfig()); |
| 1 | 102 | | var (cluster, threatClusterData) = MakeClusterWithThreats(threat); |
| | 103 | |
|
| 1 | 104 | | var carrier = (CarrierInterceptor)CreateTestInterceptor(CreateCarrierConfig()); |
| 1 | 105 | | var interceptorClusterMap = new Dictionary<Interceptor, Cluster> { [carrier] = cluster }; |
| 1 | 106 | | SetPrivateField(_iads, "_interceptorClusterMap", interceptorClusterMap); |
| | 107 | |
|
| 1 | 108 | | carrier.AssignTarget(threatClusterData.Centroid); |
| 1 | 109 | | threatClusterData.AssignInterceptor(carrier); |
| | 110 | |
|
| 1 | 111 | | threat.TerminateAgent(); |
| 1 | 112 | | _iads.LateUpdate(); |
| | 113 | |
|
| 1 | 114 | | Assert.IsFalse(carrier.HasAssignedTarget(), "Carrier should be unassigned (ballistic)."); |
| | 115 | |
|
| 1 | 116 | | var map = GetPrivateField<Dictionary<Interceptor, Cluster>>(_iads, "_interceptorClusterMap"); |
| 1 | 117 | | Assert.IsFalse(map.ContainsKey(carrier), "Carrier should be removed from cluster mapping."); |
| | 118 | |
|
| 1 | 119 | | Assert.IsFalse(_iads.ShouldLaunchSubmunitions(carrier), |
| | 120 | | "Carriers without cluster mapping should not launch submunitions."); |
| 1 | 121 | | } |
| | 122 | | } |