< Summary

Class:ThreatClusterData
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/IADS/ThreatClusterData.cs
Covered lines:29
Uncovered lines:2
Coverable lines:31
Total lines:73
Line coverage:93.5% (29 of 31)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:9
Method coverage:77.7% (7 of 9)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ThreatClusterData(...)0%110100%
UpdateCentroid()0%110100%
AssignInterceptor(...)0%220100%
RemoveInterceptor(...)0%550100%

File(s)

/github/workspace/Assets/Scripts/IADS/ThreatClusterData.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using UnityEngine;
 4
 5[System.Serializable]
 6public enum ThreatClusterStatus { UNASSIGNED, ASSIGNED, DELEGATED }
 7
 8[System.Serializable]
 9public class ThreatClusterData {
 10  private Cluster _cluster;
 11
 12  // The agent tracks the centroid of the cluster.
 13  private Agent _agent;
 14
 15  [SerializeField]
 116  private ThreatClusterStatus _status = ThreatClusterStatus.UNASSIGNED;
 17
 18  [SerializeField]
 119  private List<Interceptor> _assignedInterceptors = new List<Interceptor>();
 20
 221  public ThreatClusterData(Cluster cluster) {
 122    _cluster = cluster;
 123    _agent = SimManager.Instance.CreateDummyAgent(cluster.Centroid(), cluster.Velocity());
 124  }
 25
 26  public Cluster Cluster {
 027    get { return _cluster; }
 28  }
 29
 30  public Agent Centroid {
 331    get { return _agent; }
 32  }
 33
 34  public ThreatClusterStatus Status {
 035    get { return _status; }
 36  }
 37
 38  public int AssignedInterceptorCount {
 339    get { return _assignedInterceptors.Count; }
 40  }
 41
 42  // Read-only view of interceptors currently assigned to this cluster.
 43  public IReadOnlyList<Interceptor> AssignedInterceptors {
 344    get { return _assignedInterceptors; }
 45  }
 46
 147  public void UpdateCentroid() {
 148    _agent.SetPosition(_cluster.Centroid());
 149    _agent.SetVelocity(_cluster.Velocity());
 150  }
 51
 152  public void AssignInterceptor(Interceptor interceptor) {
 153    _status = ThreatClusterStatus.ASSIGNED;
 154    _assignedInterceptors.Add(interceptor);
 55
 56    // Assign the interceptor to all threats within the cluster.
 657    foreach (var threat in _cluster.Threats.ToList()) {
 158      threat.AddInterceptor(interceptor);
 159    }
 160  }
 61
 162  public void RemoveInterceptor(Interceptor interceptor, bool delegated = false) {
 163    _assignedInterceptors.Remove(interceptor);
 264    if (AssignedInterceptorCount == 0) {
 165      _status = delegated ? ThreatClusterStatus.DELEGATED : ThreatClusterStatus.UNASSIGNED;
 166    }
 67
 68    // Remove the interceptor from all threats within the cluster.
 669    foreach (var threat in _cluster.Threats.ToList()) {
 170      threat.RemoveInterceptor(interceptor);
 171    }
 172  }
 73}