< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Target_At_Boresight()0%110100%
Target_At_Starboard()0%110100%
Target_At_Elevation()0%110100%

File(s)

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

#LineLine coverage
 1using NUnit.Framework;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using UnityEngine.TestTools;
 5using System.Linq;
 6
 7public class TransformationTests : AgentTestBase {
 8  [Test]
 19  public void Target_At_Boresight() {
 10    // Create agent
 111    DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>();
 112    Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>();
 113    agent.transform.position = new Vector3(0, 0, 0);
 114    agentRb.linearVelocity = new Vector3(0, 0, 0);
 115    InvokePrivateMethod(agent, "Start");
 16
 17    // Create target
 118    DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>();
 119    target.SetPosition(new Vector3(0, 0, 20));
 120    Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>();
 121    targetRb.linearVelocity = new Vector3(0, 20, -1);
 122    InvokePrivateMethod(target, "Start");
 23
 24    // Find the relative transformation to the target
 125    Transformation relativeTransformation = agent.GetRelativeTransformation(target);
 26
 27    // Assert
 128    Assert.AreEqual(relativeTransformation.position.cartesian,
 29                    target.transform.position - agent.transform.position);
 130    Assert.AreEqual(relativeTransformation.position.range, 20);
 131    Assert.AreEqual(relativeTransformation.position.azimuth, 0);
 132    Assert.AreEqual(relativeTransformation.position.elevation, 0);
 133    Assert.AreEqual(relativeTransformation.velocity.cartesian,
 34                    target.GetVelocity() - agent.GetVelocity());
 135    Assert.AreEqual(relativeTransformation.velocity.range, -1);
 136    Assert.AreEqual(relativeTransformation.velocity.azimuth, 0);
 137    Assert.AreEqual(relativeTransformation.velocity.elevation, 1);
 138  }
 39
 40  [Test]
 141  public void Target_At_Starboard() {
 42    // Create agent
 143    DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>();
 144    Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>();
 145    agent.transform.position = new Vector3(0, 0, 0);
 146    agentRb.linearVelocity = new Vector3(0, 0, 0);
 47
 48    // Create target
 149    DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>();
 150    target.SetPosition(new Vector3(20, 0, 0));
 151    Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>();
 152    targetRb.linearVelocity = new Vector3(0, 0, 20);
 53
 54    // Find the relative transformation to the target
 155    Transformation relativeTransformation = agent.GetRelativeTransformation(target);
 56
 57    // Assert
 158    Assert.AreEqual(relativeTransformation.position.cartesian,
 59                    target.transform.position - agent.transform.position);
 160    Assert.AreEqual(relativeTransformation.position.range, 20);
 161    Assert.AreEqual(relativeTransformation.position.azimuth, Mathf.PI / 2);
 162    Assert.AreEqual(relativeTransformation.position.elevation, 0);
 163    Assert.AreEqual(relativeTransformation.velocity.cartesian,
 64                    target.GetVelocity() - agent.GetVelocity());
 165    Assert.AreEqual(relativeTransformation.velocity.range, 0);
 166    Assert.AreEqual(relativeTransformation.velocity.azimuth, -1);
 167    Assert.AreEqual(relativeTransformation.velocity.elevation, 0);
 168  }
 69
 70  [Test]
 171  public void Target_At_Elevation() {
 72    // Create agent
 173    DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>();
 174    Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>();
 175    agent.transform.position = new Vector3(0, 0, 0);
 176    agentRb.linearVelocity = new Vector3(0, 0, 0);
 177    InvokePrivateMethod(agent, "Start");
 78
 79    // Create target
 180    DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>();
 181    target.SetPosition(new Vector3(0, 20, 0));
 182    Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>();
 183    targetRb.linearVelocity = new Vector3(0, 0, 20);
 184    InvokePrivateMethod(target, "Start");
 85
 86    // Find the relative transformation to the target
 187    Transformation relativeTransformation = agent.GetRelativeTransformation(target);
 88
 89    // Assert
 190    Assert.AreEqual(relativeTransformation.position.cartesian,
 91                    target.transform.position - agent.transform.position);
 192    Assert.AreEqual(relativeTransformation.position.range, 20);
 193    Assert.AreEqual(relativeTransformation.position.azimuth, 0);
 194    Assert.AreEqual(relativeTransformation.position.elevation, Mathf.PI / 2);
 195    Assert.AreEqual(relativeTransformation.velocity.cartesian,
 96                    target.GetVelocity() - agent.GetVelocity());
 197    Assert.AreEqual(relativeTransformation.velocity.range, 0);
 198    Assert.AreEqual(relativeTransformation.velocity.azimuth, 0);
 199    Assert.AreEqual(relativeTransformation.velocity.elevation, -1);
 1100  }
 101}