CSVBlockReaderTest.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using NUnit.Framework;
  4. using CSVReader;
  5. using UnityEngine;
  6. using UnityEngine.TestTools;
  7. using System.Threading;
  8. using System;
  9. namespace Tests
  10. {
  11. public class CSVBlockReaderTest
  12. {
  13. private SensorCSVReader sensorReader { get; set; }
  14. private EventCSVReader eventReader { get; set; }
  15. [SetUp]
  16. public void Setup()
  17. {
  18. string filenameevents = "EventTestData.csv";
  19. string filenamesensors = "SensorTestData.csv";
  20. sensorReader = new SensorCSVReader(filenamesensors);
  21. eventReader = new EventCSVReader(filenameevents);
  22. }
  23. [Test]
  24. public void ReadSensorsTest()
  25. {
  26. SensorObject[] sensors;
  27. //Read sensors
  28. sensors = sensorReader.ReadFile();
  29. Assert.AreEqual(2, sensors.Length, "instead of 2, Sensor file has " + sensors.Length + " entries");
  30. //check Entries
  31. SensorObject s1 = new SensorObject(0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
  32. SensorObject s2 = new SensorObject(1, -40.5f, 10.15f, 13.15f, 30.0f, 200.0f, 0.0f);
  33. Assert.IsTrue(sensors[0].Equals(s1));
  34. Assert.IsTrue(sensors[1].Equals(s2));
  35. //Re-Read sensors and check if unchanged
  36. sensors = sensorReader.ReadFile();
  37. Assert.AreEqual(2, sensors.Length, "instead of 2, Sensor file has " + sensors.Length + " entries");
  38. Assert.IsTrue(sensors[0].Equals(s1));
  39. Assert.IsTrue(sensors[1].Equals(s2));
  40. }
  41. [Test]
  42. public void ReadEventsTest()
  43. {
  44. EventObject[] events;
  45. //Read events
  46. events = eventReader.ReadFile();
  47. Assert.AreEqual(4, events.Length, "instead of 4, Event file has " + events.Length + " entries");
  48. //check Entries
  49. EventObject e1 = new EventObject(0, 33.5, 0.0f, 0.0f, 0.0f, CSVReader.EventType.FALLINGPERSON);
  50. EventObject e2 = new EventObject(0, 40.0, 0.0f, 0.0f, 0.0f, CSVReader.EventType.CONFETTICANNON);
  51. e2.TimestampEnd = 45.0;
  52. EventObject e3 = new EventObject(0, 50.0, 0.0f, 0.0f, 0.0f, CSVReader.EventType.EXPLOSION);
  53. e3.IdealViewingPos = new Vector3(0.0f, 20.0f, 0.0f);
  54. EventObject e4 = new EventObject(0, 66.6, 0.0f, 0.0f, 0.0f, CSVReader.EventType.CARCRASH);
  55. e4.IdealViewingPos = new Vector3(0.0f, 50.0f, 0.0f);
  56. e4.TimestampEnd = 77.7;
  57. Assert.IsTrue(events[0].Equals(e1));
  58. Assert.IsTrue(events[1].Equals(e2));
  59. Assert.IsTrue(events[2].Equals(e3));
  60. Assert.IsTrue(events[3].Equals(e4));
  61. //Re-Read sensors and check if unchanged
  62. events = eventReader.ReadFile();
  63. Assert.AreEqual(0, events.Length, "instead of 0, Event file has " + events.Length + " new entries");
  64. }
  65. [Test]
  66. public void WrongFileTest()
  67. {
  68. SensorCSVReader sensorReaderErr = new SensorCSVReader("WerBinIch");
  69. EventCSVReader eventReaderErr = new EventCSVReader("WoBinIch");
  70. Assert.IsNull(sensorReaderErr.ReadFile());
  71. Assert.IsNull(eventReaderErr.ReadFile());
  72. }
  73. [TearDown]
  74. public void TearDown()
  75. {
  76. }
  77. }
  78. }