< Summary

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

Metrics

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

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]
 17716  private ThreatClusterStatus _status = ThreatClusterStatus.UNASSIGNED;
 17
 18  [SerializeField]
 17719  private List<Interceptor> _assignedInterceptors = new List<Interceptor>();
 20
 35421  public ThreatClusterData(Cluster cluster) {
 17722    _cluster = cluster;
 17723    _agent = SimManager.Instance.CreateDummyAgent(cluster.Centroid(), cluster.Velocity());
 17724  }
 25
 26  public Cluster Cluster {
 027    get { return _cluster; }
 28  }
 29
 30  public Agent Centroid {
 031    get { return _agent; }
 32  }
 33
 34  public ThreatClusterStatus Status {
 035    get { return _status; }
 36  }
 37
 38  public int AssignedInterceptorCount {
 039    get { return _assignedInterceptors.Count; }
 40  }
 41
 42  // Read-only view of interceptors currently assigned to this cluster.
 43  public IReadOnlyList<Interceptor> AssignedInterceptors {
 044    get { return _assignedInterceptors; }
 45  }
 46
 47047  public void UpdateCentroid() {
 47048    _agent.SetPosition(_cluster.Centroid());
 47049    _agent.SetVelocity(_cluster.Velocity());
 47050  }
 51
 052  public void AssignInterceptor(Interceptor interceptor) {
 053    _status = ThreatClusterStatus.ASSIGNED;
 054    _assignedInterceptors.Add(interceptor);
 55
 56    // Assign the interceptor to all threats within the cluster.
 057    foreach (var threat in _cluster.Threats.ToList()) {
 058      threat.AddInterceptor(interceptor);
 059    }
 060  }
 61
 062  public void RemoveInterceptor(Interceptor interceptor, bool delegated = false) {
 063    _assignedInterceptors.Remove(interceptor);
 064    if (AssignedInterceptorCount == 0) {
 065      _status = delegated ? ThreatClusterStatus.DELEGATED : ThreatClusterStatus.UNASSIGNED;
 066    }
 67
 68    // Remove the interceptor from all threats within the cluster.
 069    foreach (var threat in _cluster.Threats.ToList()) {
 070      threat.RemoveInterceptor(interceptor);
 071    }
 072  }
 73}