| | | 1 | | using NUnit.Framework; |
| | | 2 | | using System.Collections; |
| | | 3 | | using System.Collections.Generic; |
| | | 4 | | using UnityEngine; |
| | | 5 | | using UnityEngine.TestTools; |
| | | 6 | | |
| | | 7 | | public class LinearExtrapolatorTests { |
| | 0 | 8 | | public static Agent GenerateAgent() { |
| | 0 | 9 | | Agent agent = new GameObject().AddComponent<DummyAgent>(); |
| | 0 | 10 | | Rigidbody rb = agent.gameObject.AddComponent<Rigidbody>(); |
| | 0 | 11 | | agent.transform.position = new Vector3(10, 0, 5); |
| | 0 | 12 | | rb.linearVelocity = new Vector3(1, -2, 2); |
| | 0 | 13 | | return agent; |
| | 0 | 14 | | } |
| | | 15 | | |
| | | 16 | | [Test] |
| | 0 | 17 | | public void TestPresent() { |
| | 0 | 18 | | Agent agent = GenerateAgent(); |
| | 0 | 19 | | LinearExtrapolator predictor = new LinearExtrapolator(agent); |
| | 0 | 20 | | PredictorState predictedState = predictor.Predict(time: 0f); |
| | 0 | 21 | | Assert.AreEqual(agent.GetPosition(), predictedState.Position); |
| | 0 | 22 | | Assert.AreEqual(agent.GetVelocity(), predictedState.Velocity); |
| | 0 | 23 | | } |
| | | 24 | | |
| | | 25 | | [Test] |
| | 0 | 26 | | public void TestPast() { |
| | 0 | 27 | | Agent agent = GenerateAgent(); |
| | 0 | 28 | | LinearExtrapolator predictor = new LinearExtrapolator(agent); |
| | 0 | 29 | | PredictorState predictedState = predictor.Predict(time: -5f); |
| | 0 | 30 | | Assert.AreEqual(new Vector3(5, 10, -5), predictedState.Position); |
| | 0 | 31 | | Assert.AreEqual(agent.GetVelocity(), predictedState.Velocity); |
| | 0 | 32 | | } |
| | | 33 | | |
| | | 34 | | [Test] |
| | 0 | 35 | | public void TestFuture() { |
| | 0 | 36 | | Agent agent = GenerateAgent(); |
| | 0 | 37 | | LinearExtrapolator predictor = new LinearExtrapolator(agent); |
| | 0 | 38 | | PredictorState predictedState = predictor.Predict(time: 10f); |
| | 0 | 39 | | Assert.AreEqual(new Vector3(20, -20, 25), predictedState.Position); |
| | 0 | 40 | | Assert.AreEqual(agent.GetVelocity(), predictedState.Velocity); |
| | 0 | 41 | | } |
| | | 42 | | } |