< Summary

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

Metrics

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

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]
 011  public override void Setup() {
 012    base.Setup();
 013    _iads = new GameObject("IADS").AddComponent<IADS>();
 014    _iads.Start();
 015  }
 16
 17  [TearDown]
 018  public override void Teardown() {
 019    base.Teardown();
 020    if (_iads != null) {
 021      GameObject.DestroyImmediate(_iads.gameObject);
 022    }
 023  }
 24
 025  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
 044  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
 086  private (Cluster, ThreatClusterData) MakeClusterWithThreats(params Threat[] threats) {
 087    var cluster = new Cluster();
 088    foreach (var threat in threats) {
 089      cluster.AddObject(threat.gameObject);
 090    }
 091    var threatClusterData = new ThreatClusterData(cluster);
 092    var clusters = new List<Cluster> { cluster };
 093    SetPrivateField(_iads, "_threatClusters", clusters);
 094    var map = new Dictionary<Cluster, ThreatClusterData> { [cluster] = threatClusterData };
 095    SetPrivateField(_iads, "_threatClusterMap", map);
 096    return (cluster, threatClusterData);
 097  }
 98
 99  [Test]
 0100  public void Carrier_Unassigned_WhenClusterFullyDestroyed() {
 0101    var threat = CreateTestThreat(CreateThreatConfig());
 0102    var (cluster, threatClusterData) = MakeClusterWithThreats(threat);
 103
 0104    var carrier = (CarrierInterceptor)CreateTestInterceptor(CreateCarrierConfig());
 0105    var interceptorClusterMap = new Dictionary<Interceptor, Cluster> { [carrier] = cluster };
 0106    SetPrivateField(_iads, "_interceptorClusterMap", interceptorClusterMap);
 107
 0108    carrier.AssignTarget(threatClusterData.Centroid);
 0109    threatClusterData.AssignInterceptor(carrier);
 110
 0111    threat.TerminateAgent();
 0112    _iads.LateUpdate();
 113
 0114    Assert.IsFalse(carrier.HasAssignedTarget(), "Carrier should be unassigned (ballistic).");
 115
 0116    var map = GetPrivateField<Dictionary<Interceptor, Cluster>>(_iads, "_interceptorClusterMap");
 0117    Assert.IsFalse(map.ContainsKey(carrier), "Carrier should be removed from cluster mapping.");
 118
 0119    Assert.IsFalse(_iads.ShouldLaunchSubmunitions(carrier),
 120                   "Carriers without cluster mapping should not launch submunitions.");
 0121  }
 122}