using System.Collections; using System.Collections.Generic; using CSVReader; using NUnit.Framework; using UnityEngine; using UnityEngine.TestTools; namespace Tests { public class MapSensorTest { IMapSensor mapper; private GameObject sensorDummy; [SetUp] public void SetUp() { sensorDummy = Resources.Load("Prefabs/Sensor"); mapper = new MapSensor(); } // A Test behaves as an ordinary method [Test] public void NoRotationDifference() { Dictionary sensors = new Dictionary(); var instanceDummy = MonoBehaviour.Instantiate(sensorDummy); instanceDummy.transform.position = new Vector3(3, 0, 3); sensors.Add(0, instanceDummy); mapper.SetSensorList(sensors); InputObject input = new InputObject(0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0); var output = mapper.MapToWorldPositions(new List() { input }); Assert.AreEqual(1, output.Count); Assert.AreEqual(0, Vector3.Distance(new Vector3(5, 0, 5), output[0].Pos), 0.00001); } [Test] public void WithRotationDifference() { Dictionary sensors = new Dictionary(); var instanceDummy = MonoBehaviour.Instantiate(sensorDummy); instanceDummy.transform.position = new Vector3(3, 0, 3); //Rotate Lokal Grid 90Degress around Y axis instanceDummy.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up); sensors.Add(0, instanceDummy); mapper.SetSensorList(sensors); InputObject input = new InputObject(0, 0, 2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0); var output = mapper.MapToWorldPositions(new List() { input }); Assert.AreEqual(1, output.Count); Assert.AreEqual(0, Vector3.Distance(new Vector3(5, 0, 5), output[0].Pos), 0.00001); } [Test] public void WithRotationDifferenceAndRotationOfObject() { Dictionary sensors = new Dictionary(); var instanceDummy = MonoBehaviour.Instantiate(sensorDummy); instanceDummy.transform.position = new Vector3(3, 0, 3); //Rotate Lokal Grid 90Degress around Y axis instanceDummy.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up); sensors.Add(0, instanceDummy); mapper.SetSensorList(sensors); InputObject input = new InputObject(0, 0, 2, 0, -2, 0, -90, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0); var output = mapper.MapToWorldPositions(new List() { input }); Assert.AreEqual(1, output.Count); Assert.AreEqual(0, Vector3.Distance(new Vector3(0, -90, 0), output[0].Rot), 0.00001); } } }