< Summary

Class:IterativeLaunchPlannerTest
Assembly:bamlab.test.editmode
File(s):/github/workspace/Assets/Tests/EditMode/IterativeLaunchPlannerTest.cs
Covered lines:60
Uncovered lines:0
Coverable lines:60
Total lines:97
Line coverage:100% (60 of 60)
Covered branches:0
Total branches:0
Covered methods:10
Total methods:10
Method coverage:100% (10 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DummyLaunchAngleDataInterpolator()0%110100%
GenerateData()0%110100%
IterativeLaunchPlannerTest()0%110100%
GenerateAgent(...)0%110100%
TestInterceptAtDataPoint()0%110100%
TestInterceptAroundDataPoint()0%110100%
TestInterceptAcrossMultipleDataPoints()0%110100%
TestLaunchDivergingFromOrigin()0%110100%
TestNoLaunchDivergingFromInterceptPoint()0%110100%
TestNoLaunchTooFarFromInterceptPoint()0%110100%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using UnityEngine.TestTools;
 7
 8public class IterativeLaunchPlannerTest {
 9  private class DummyLaunchAngleDataInterpolator : LaunchAngleDataInterpolator {
 310    public DummyLaunchAngleDataInterpolator() : base() {}
 11
 12    // Generate the list of launch angle data points to interpolate.
 113    protected override List<LaunchAngleDataPoint> GenerateData() {
 114      return new List<LaunchAngleDataPoint> {
 15        new LaunchAngleDataPoint(new LaunchAngleInput(distance: 1, altitude: 100),
 16                                 new LaunchAngleOutput(launchAngle: 90, timeToPosition: 10)),
 17        new LaunchAngleDataPoint(new LaunchAngleInput(distance: 60, altitude: 1),
 18                                 new LaunchAngleOutput(launchAngle: 20, timeToPosition: 13)),
 19        new LaunchAngleDataPoint(new LaunchAngleInput(distance: 80, altitude: 1),
 20                                 new LaunchAngleOutput(launchAngle: 15, timeToPosition: 16)),
 21        new LaunchAngleDataPoint(new LaunchAngleInput(distance: 100, altitude: 1),
 22                                 new LaunchAngleOutput(launchAngle: 10, timeToPosition: 20)),
 23      };
 124    }
 25  }
 26
 127  private static ILaunchAnglePlanner _launchAnglePlanner = new DummyLaunchAngleDataInterpolator();
 28
 629  public static Agent GenerateAgent(in Vector3 position, in Vector3 velocity) {
 630    Agent agent = new GameObject().AddComponent<DummyAgent>();
 631    Rigidbody rb = agent.gameObject.AddComponent<Rigidbody>();
 632    agent.transform.position = position;
 633    rb.linearVelocity = velocity;
 634    return agent;
 635  }
 36
 37  [Test]
 138  public void TestInterceptAtDataPoint() {
 139    Agent agent = GenerateAgent(position: new Vector3(1, 110, 0), velocity: new Vector3(0, -1, 0));
 140    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 141    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 142    LaunchPlan plan = planner.Plan();
 143    Assert.IsTrue(plan.ShouldLaunch);
 144    Assert.AreEqual(90, plan.LaunchAngle);
 145    Assert.AreEqual(new Vector3(1, 100, 0), plan.InterceptPosition);
 146  }
 47
 48  [Test]
 149  public void TestInterceptAroundDataPoint() {
 150    Agent agent =
 51        GenerateAgent(position: new Vector3(1, 110, 0), velocity: new Vector3(0, -1.1f, 0));
 152    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 153    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 154    LaunchPlan plan = planner.Plan();
 155    Assert.IsTrue(plan.ShouldLaunch);
 156    Assert.AreEqual(90, plan.LaunchAngle);
 157    Assert.AreEqual(new Vector3(1, 99, 0), plan.InterceptPosition);
 158  }
 59
 60  [Test]
 161  public void TestInterceptAcrossMultipleDataPoints() {
 162    Agent agent = GenerateAgent(position: new Vector3(126, 1, 0), velocity: new Vector3(-5, 0, 0));
 163    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 164    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 165    LaunchPlan plan = planner.Plan();
 166    Assert.IsTrue(plan.ShouldLaunch);
 167    Assert.AreEqual(20, plan.LaunchAngle);
 168    Assert.AreEqual(new Vector3(61, 1, 0), plan.InterceptPosition);
 169  }
 70
 71  [Test]
 172  public void TestLaunchDivergingFromOrigin() {
 173    Agent agent = GenerateAgent(position: new Vector3(0, 1, -80), velocity: new Vector3(0, 0, -1));
 174    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 175    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 176    LaunchPlan plan = planner.Plan();
 177    Assert.IsFalse(plan.ShouldLaunch);
 178  }
 79
 80  [Test]
 181  public void TestNoLaunchDivergingFromInterceptPoint() {
 182    Agent agent = GenerateAgent(position: new Vector3(1, 105, 0), velocity: new Vector3(0, 1, 0));
 183    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 184    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 185    LaunchPlan plan = planner.Plan();
 186    Assert.IsFalse(plan.ShouldLaunch);
 187  }
 88
 89  [Test]
 190  public void TestNoLaunchTooFarFromInterceptPoint() {
 191    Agent agent = GenerateAgent(position: new Vector3(1, 2000, 0), velocity: new Vector3(0, -1, 0));
 192    LinearExtrapolator predictor = new LinearExtrapolator(agent);
 193    IterativeLaunchPlanner planner = new IterativeLaunchPlanner(_launchAnglePlanner, predictor);
 194    LaunchPlan plan = planner.Plan();
 195    Assert.IsFalse(plan.ShouldLaunch);
 196  }
 97}