MapSensorTest.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using CSVReader;
  4. using NUnit.Framework;
  5. using UnityEngine;
  6. using UnityEngine.TestTools;
  7. namespace Tests
  8. {
  9. public class MapSensorTest
  10. {
  11. IMapSensor mapper;
  12. private GameObject sensorDummy;
  13. [SetUp]
  14. public void SetUp()
  15. {
  16. sensorDummy = Resources.Load<GameObject>("Prefabs/Sensor");
  17. mapper = new MapSensor();
  18. }
  19. // A Test behaves as an ordinary method
  20. [Test]
  21. public void NoRotationDifference()
  22. {
  23. Dictionary<int, GameObject> sensors = new Dictionary<int, GameObject>();
  24. var instanceDummy = MonoBehaviour.Instantiate(sensorDummy);
  25. instanceDummy.transform.position = new Vector3(3, 0, 3);
  26. sensors.Add(0, instanceDummy);
  27. mapper.SetSensorList(sensors);
  28. InputObject input = new InputObject(0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0);
  29. var output = mapper.MapToWorldPositions(new List<InputObject>() { input });
  30. Assert.AreEqual(1, output.Count);
  31. Assert.AreEqual(0, Vector3.Distance(new Vector3(5, 0, 5), output[0].Pos), 0.00001);
  32. }
  33. [Test]
  34. public void WithRotationDifference()
  35. {
  36. Dictionary<int, GameObject> sensors = new Dictionary<int, GameObject>();
  37. var instanceDummy = MonoBehaviour.Instantiate(sensorDummy);
  38. instanceDummy.transform.position = new Vector3(3, 0, 3);
  39. //Rotate Lokal Grid 90Degress around Y axis
  40. instanceDummy.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
  41. sensors.Add(0, instanceDummy);
  42. mapper.SetSensorList(sensors);
  43. InputObject input = new InputObject(0, 0, 2, 0, -2, 0, 0, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0);
  44. var output = mapper.MapToWorldPositions(new List<InputObject>() { input });
  45. Assert.AreEqual(1, output.Count);
  46. Assert.AreEqual(0, Vector3.Distance(new Vector3(5, 0, 5), output[0].Pos), 0.00001);
  47. }
  48. [Test]
  49. public void WithRotationDifferenceAndRotationOfObject()
  50. {
  51. Dictionary<int, GameObject> sensors = new Dictionary<int, GameObject>();
  52. var instanceDummy = MonoBehaviour.Instantiate(sensorDummy);
  53. instanceDummy.transform.position = new Vector3(3, 0, 3);
  54. //Rotate Lokal Grid 90Degress around Y axis
  55. instanceDummy.transform.rotation = Quaternion.AngleAxis(-90, Vector3.up);
  56. sensors.Add(0, instanceDummy);
  57. mapper.SetSensorList(sensors);
  58. InputObject input = new InputObject(0, 0, 2, 0, -2, 0, -90, 0, 0, 0, 0, 0, 0, EntityType.PERSON, 0);
  59. var output = mapper.MapToWorldPositions(new List<InputObject>() { input });
  60. Assert.AreEqual(1, output.Count);
  61. Assert.AreEqual(0, Vector3.Distance(new Vector3(0, -90, 0), output[0].Rot), 0.00001);
  62. }
  63. }
  64. }