< Summary

Class:IADSClusterCleanupTests
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/IADSClusterCleanupTests.cs
Covered lines:40
Uncovered lines:1
Coverable lines:41
Total lines:122
Line coverage:97.5% (40 of 41)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:7
Method coverage:85.7% (6 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Setup()0%110100%
Teardown()0%220100%
CreateThreatConfig()0%110100%
CreateCarrierConfig()0%110100%
CreateMissileConfig()0%2100%
MakeClusterWithThreats(...)0%220100%
Carrier_Unassigned_WhenClusterFullyDestroyed()0%110100%

File(s)

/github/workspace/Assets/Tests/EditMode/IADSClusterCleanupTests.cs

#LineLine coverage
 1using NUnit.Framework;
 2using UnityEngine;
 3using System.Collections.Generic;
 4using System.Linq;
 5using Configs;
 6
 7public class IADSClusterCleanupTests : AgentTestBase {
 8  private IADS _iads;
 9
 10  [SetUp]
 111  public override void Setup() {
 112    base.Setup();
 113    _iads = new GameObject("IADS").AddComponent<IADS>();
 114    _iads.Start();
 115  }
 16
 17  [TearDown]
 118  public override void Teardown() {
 119    base.Teardown();
 220    if (_iads != null) {
 121      GameObject.DestroyImmediate(_iads.gameObject);
 122    }
 123  }
 24
 125  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
 144  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
 065  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
 186  private (Cluster, ThreatClusterData) MakeClusterWithThreats(params Threat[] threats) {
 187    var cluster = new Cluster();
 688    foreach (var threat in threats) {
 189      cluster.AddObject(threat.gameObject);
 190    }
 191    var threatClusterData = new ThreatClusterData(cluster);
 192    var clusters = new List<Cluster> { cluster };
 193    SetPrivateField(_iads, "_threatClusters", clusters);
 194    var map = new Dictionary<Cluster, ThreatClusterData> { [cluster] = threatClusterData };
 195    SetPrivateField(_iads, "_threatClusterMap", map);
 196    return (cluster, threatClusterData);
 197  }
 98
 99  [Test]
 1100  public void Carrier_Unassigned_WhenClusterFullyDestroyed() {
 1101    var threat = CreateTestThreat(CreateThreatConfig());
 1102    var (cluster, threatClusterData) = MakeClusterWithThreats(threat);
 103
 1104    var carrier = (CarrierInterceptor)CreateTestInterceptor(CreateCarrierConfig());
 1105    var interceptorClusterMap = new Dictionary<Interceptor, Cluster> { [carrier] = cluster };
 1106    SetPrivateField(_iads, "_interceptorClusterMap", interceptorClusterMap);
 107
 1108    carrier.AssignTarget(threatClusterData.Centroid);
 1109    threatClusterData.AssignInterceptor(carrier);
 110
 1111    threat.TerminateAgent();
 1112    _iads.LateUpdate();
 113
 1114    Assert.IsFalse(carrier.HasAssignedTarget(), "Carrier should be unassigned (ballistic).");
 115
 1116    var map = GetPrivateField<Dictionary<Interceptor, Cluster>>(_iads, "_interceptorClusterMap");
 1117    Assert.IsFalse(map.ContainsKey(carrier), "Carrier should be removed from cluster mapping.");
 118
 1119    Assert.IsFalse(_iads.ShouldLaunchSubmunitions(carrier),
 120                   "Carriers without cluster mapping should not launch submunitions.");
 1121  }
 122}