| | 1 | | using NUnit.Framework; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.TestTools; |
| | 5 | | using System.Linq; |
| | 6 | |
|
| | 7 | | public class TransformationTests : AgentTestBase { |
| | 8 | | [Test] |
| 0 | 9 | | public void Target_At_Boresight() { |
| | 10 | | // Create agent |
| 0 | 11 | | DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>(); |
| 0 | 12 | | Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>(); |
| 0 | 13 | | agent.transform.position = new Vector3(0, 0, 0); |
| 0 | 14 | | agentRb.linearVelocity = new Vector3(0, 0, 0); |
| 0 | 15 | | InvokePrivateMethod(agent, "Start"); |
| | 16 | |
|
| | 17 | | // Create target |
| 0 | 18 | | DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>(); |
| 0 | 19 | | target.SetPosition(new Vector3(0, 0, 20)); |
| 0 | 20 | | Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>(); |
| 0 | 21 | | targetRb.linearVelocity = new Vector3(0, 20, -1); |
| 0 | 22 | | InvokePrivateMethod(target, "Start"); |
| | 23 | |
|
| | 24 | | // Find the relative transformation to the target |
| 0 | 25 | | Transformation relativeTransformation = agent.GetRelativeTransformation(target); |
| | 26 | |
|
| | 27 | | // Assert |
| 0 | 28 | | Assert.AreEqual(relativeTransformation.position.cartesian, |
| | 29 | | target.transform.position - agent.transform.position); |
| 0 | 30 | | Assert.AreEqual(relativeTransformation.position.range, 20); |
| 0 | 31 | | Assert.AreEqual(relativeTransformation.position.azimuth, 0); |
| 0 | 32 | | Assert.AreEqual(relativeTransformation.position.elevation, 0); |
| 0 | 33 | | Assert.AreEqual(relativeTransformation.velocity.cartesian, |
| | 34 | | target.GetVelocity() - agent.GetVelocity()); |
| 0 | 35 | | Assert.AreEqual(relativeTransformation.velocity.range, -1); |
| 0 | 36 | | Assert.AreEqual(relativeTransformation.velocity.azimuth, 0); |
| 0 | 37 | | Assert.AreEqual(relativeTransformation.velocity.elevation, 1); |
| 0 | 38 | | } |
| | 39 | |
|
| | 40 | | [Test] |
| 0 | 41 | | public void Target_At_Starboard() { |
| | 42 | | // Create agent |
| 0 | 43 | | DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>(); |
| 0 | 44 | | Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>(); |
| 0 | 45 | | agent.transform.position = new Vector3(0, 0, 0); |
| 0 | 46 | | agentRb.linearVelocity = new Vector3(0, 0, 0); |
| | 47 | |
|
| | 48 | | // Create target |
| 0 | 49 | | DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>(); |
| 0 | 50 | | target.SetPosition(new Vector3(20, 0, 0)); |
| 0 | 51 | | Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>(); |
| 0 | 52 | | targetRb.linearVelocity = new Vector3(0, 0, 20); |
| | 53 | |
|
| | 54 | | // Find the relative transformation to the target |
| 0 | 55 | | Transformation relativeTransformation = agent.GetRelativeTransformation(target); |
| | 56 | |
|
| | 57 | | // Assert |
| 0 | 58 | | Assert.AreEqual(relativeTransformation.position.cartesian, |
| | 59 | | target.transform.position - agent.transform.position); |
| 0 | 60 | | Assert.AreEqual(relativeTransformation.position.range, 20); |
| 0 | 61 | | Assert.AreEqual(relativeTransformation.position.azimuth, Mathf.PI / 2); |
| 0 | 62 | | Assert.AreEqual(relativeTransformation.position.elevation, 0); |
| 0 | 63 | | Assert.AreEqual(relativeTransformation.velocity.cartesian, |
| | 64 | | target.GetVelocity() - agent.GetVelocity()); |
| 0 | 65 | | Assert.AreEqual(relativeTransformation.velocity.range, 0); |
| 0 | 66 | | Assert.AreEqual(relativeTransformation.velocity.azimuth, -1); |
| 0 | 67 | | Assert.AreEqual(relativeTransformation.velocity.elevation, 0); |
| 0 | 68 | | } |
| | 69 | |
|
| | 70 | | [Test] |
| 0 | 71 | | public void Target_At_Elevation() { |
| | 72 | | // Create agent |
| 0 | 73 | | DummyAgent agent = new GameObject("Agent").AddComponent<DummyAgent>(); |
| 0 | 74 | | Rigidbody agentRb = agent.gameObject.AddComponent<Rigidbody>(); |
| 0 | 75 | | agent.transform.position = new Vector3(0, 0, 0); |
| 0 | 76 | | agentRb.linearVelocity = new Vector3(0, 0, 0); |
| 0 | 77 | | InvokePrivateMethod(agent, "Start"); |
| | 78 | |
|
| | 79 | | // Create target |
| 0 | 80 | | DummyAgent target = new GameObject("Target").AddComponent<DummyAgent>(); |
| 0 | 81 | | target.SetPosition(new Vector3(0, 20, 0)); |
| 0 | 82 | | Rigidbody targetRb = target.gameObject.AddComponent<Rigidbody>(); |
| 0 | 83 | | targetRb.linearVelocity = new Vector3(0, 0, 20); |
| 0 | 84 | | InvokePrivateMethod(target, "Start"); |
| | 85 | |
|
| | 86 | | // Find the relative transformation to the target |
| 0 | 87 | | Transformation relativeTransformation = agent.GetRelativeTransformation(target); |
| | 88 | |
|
| | 89 | | // Assert |
| 0 | 90 | | Assert.AreEqual(relativeTransformation.position.cartesian, |
| | 91 | | target.transform.position - agent.transform.position); |
| 0 | 92 | | Assert.AreEqual(relativeTransformation.position.range, 20); |
| 0 | 93 | | Assert.AreEqual(relativeTransformation.position.azimuth, 0); |
| 0 | 94 | | Assert.AreEqual(relativeTransformation.position.elevation, Mathf.PI / 2); |
| 0 | 95 | | Assert.AreEqual(relativeTransformation.velocity.cartesian, |
| | 96 | | target.GetVelocity() - agent.GetVelocity()); |
| 0 | 97 | | Assert.AreEqual(relativeTransformation.velocity.range, 0); |
| 0 | 98 | | Assert.AreEqual(relativeTransformation.velocity.azimuth, 0); |
| 0 | 99 | | Assert.AreEqual(relativeTransformation.velocity.elevation, -1); |
| 0 | 100 | | } |
| | 101 | | } |