< Summary

Class:RoundRobinAssignment
Assembly:bamlab.micromissiles
File(s):/github/workspace/Assets/Scripts/Assignment/RoundRobinAssignment.cs
Covered lines:0
Uncovered lines:17
Coverable lines:17
Total lines:45
Line coverage:0% (0 of 17)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:2
Method coverage:0% (0 of 2)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
RoundRobinAssignment()0%2100%
Assign(...)0%20400%

File(s)

/github/workspace/Assets/Scripts/Assignment/RoundRobinAssignment.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using UnityEngine;
 4using System.Diagnostics.Contracts;
 5
 6// The round-robin assignment class assigns interceptors to the targets in a
 7// round-robin order using the new paradigm.
 8public class RoundRobinAssignment : IAssignment {
 9  // Previous target index that was assigned.
 010  private int prevTargetIndex = -1;
 11
 12  // Assign a target to each interceptor that has not been assigned a target yet.
 13  [Pure]
 14  public IEnumerable<IAssignment.AssignmentItem> Assign(in IReadOnlyList<Interceptor> interceptors,
 015                                                        in IReadOnlyList<ThreatData> targets) {
 016    List<IAssignment.AssignmentItem> assignments = new List<IAssignment.AssignmentItem>();
 17
 18    // Get the list of interceptors that are available for assignment.
 019    List<Interceptor> assignableInterceptors = IAssignment.GetAssignableInterceptors(interceptors);
 020    if (assignableInterceptors.Count == 0) {
 021      return assignments;
 22    }
 23
 24    // Get the list of active threats that need to be addressed.
 025    List<ThreatData> activeThreats = IAssignment.GetActiveThreats(targets);
 026    if (activeThreats.Count == 0) {
 027      return assignments;
 28    }
 29
 30    // Perform round-robin assignment.
 031    foreach (Interceptor interceptor in assignableInterceptors) {
 32      // Determine the next target index in a round-robin fashion.
 033      int nextTargetIndex = (prevTargetIndex + 1) % activeThreats.Count;
 034      ThreatData selectedThreat = activeThreats[nextTargetIndex];
 35
 36      // Assign the interceptor to the selected threat.
 037      assignments.Add(new IAssignment.AssignmentItem(interceptor, selectedThreat.Threat));
 38
 39      // Update the previous target index.
 040      prevTargetIndex = nextTargetIndex;
 041    }
 42
 043    return assignments;
 044  }
 45}