| | 1 | | using System; |
| | 2 | | using System.Reflection; |
| | 3 | | using NUnit.Framework; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | public abstract class AgentTestBase : TestBase { |
| | 7 | | protected SimManager _simManager; |
| | 8 | |
|
| | 9 | | [SetUp] |
| 11 | 10 | | public virtual void Setup() { |
| | 11 | | // Initialize the simulation manager. |
| 11 | 12 | | var simManagerGameObject = new GameObject("SimManager"); |
| 11 | 13 | | _simManager = simManagerGameObject.AddComponent<SimManager>(); |
| 11 | 14 | | _simManager.SimulationConfig = new Configs.SimulationConfig(); |
| 11 | 15 | | SimManager.Instance = _simManager; |
| 11 | 16 | | } |
| | 17 | |
|
| | 18 | | [TearDown] |
| 11 | 19 | | public virtual void Teardown() { |
| | 20 | | // Clean up the simulation manager. |
| 21 | 21 | | if (_simManager != null) { |
| 10 | 22 | | GameObject.DestroyImmediate(_simManager.gameObject); |
| 10 | 23 | | } |
| 11 | 24 | | } |
| | 25 | |
|
| 1 | 26 | | protected Interceptor CreateTestInterceptor(Configs.AgentConfig config) { |
| 1 | 27 | | Interceptor interceptor = SimManager.Instance.CreateInterceptor( |
| | 28 | | config, new Simulation.State() { Position = Coordinates3.ToProto(Vector3.zero), |
| | 29 | | Velocity = Coordinates3.ToProto(Vector3.zero) }); |
| 1 | 30 | | InvokePrivateMethod(interceptor, "Start"); |
| 1 | 31 | | InvokePrivateMethod(interceptor.gameObject.GetComponent<Sensor>(), "Start"); |
| 1 | 32 | | return interceptor; |
| 1 | 33 | | } |
| | 34 | |
|
| 15 | 35 | | protected Threat CreateTestThreat(Configs.AgentConfig config) { |
| 15 | 36 | | Threat threat = SimManager.Instance.CreateThreat(config); |
| 15 | 37 | | InvokePrivateMethod(threat, "Start"); |
| 15 | 38 | | InvokePrivateMethod(threat.gameObject.GetComponent<Sensor>(), "Start"); |
| 15 | 39 | | return threat; |
| 15 | 40 | | } |
| | 41 | | } |