12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- using System.Collections;
- using System.Collections.Generic;
- using NUnit.Framework;
- using CSVReader;
- using UnityEngine;
- using UnityEngine.TestTools;
- using System.Threading;
- using System;
- namespace Tests
- {
- public class CSVBlockReaderTest
- {
- private SensorCSVReader sensorReader { get; set; }
- private EventCSVReader eventReader { get; set; }
- [SetUp]
- public void Setup()
- {
- string filenameevents = "EventTestData.csv";
- string filenamesensors = "SensorTestData.csv";
- sensorReader = new SensorCSVReader(filenamesensors);
- eventReader = new EventCSVReader(filenameevents);
- }
- [Test]
- public void ReadSensorsTest()
- {
- SensorObject[] sensors;
- //Read sensors
- sensors = sensorReader.ReadFile();
- Assert.AreEqual(2, sensors.Length, "instead of 2, Sensor file has " + sensors.Length + " entries");
- //check Entries
- SensorObject s1 = new SensorObject(0, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f);
- SensorObject s2 = new SensorObject(1, -40.5f, 10.15f, 13.15f, 30.0f, 200.0f, 0.0f);
- Assert.IsTrue(sensors[0].Equals(s1));
- Assert.IsTrue(sensors[1].Equals(s2));
- //Re-Read sensors and check if unchanged
- sensors = sensorReader.ReadFile();
- Assert.AreEqual(2, sensors.Length, "instead of 2, Sensor file has " + sensors.Length + " entries");
- Assert.IsTrue(sensors[0].Equals(s1));
- Assert.IsTrue(sensors[1].Equals(s2));
- }
- [Test]
- public void ReadEventsTest()
- {
- EventObject[] events;
- //Read events
- events = eventReader.ReadFile();
- Assert.AreEqual(4, events.Length, "instead of 4, Event file has " + events.Length + " entries");
- //check Entries
- EventObject e1 = new EventObject(0, 33.5, 0.0f, 0.0f, 0.0f, CSVReader.EventType.FALLINGPERSON);
- EventObject e2 = new EventObject(0, 40.0, 0.0f, 0.0f, 0.0f, CSVReader.EventType.CONFETTICANNON);
- e2.TimestampEnd = 45.0;
- EventObject e3 = new EventObject(0, 50.0, 0.0f, 0.0f, 0.0f, CSVReader.EventType.EXPLOSION);
- e3.IdealViewingPos = new Vector3(0.0f, 20.0f, 0.0f);
- EventObject e4 = new EventObject(0, 66.6, 0.0f, 0.0f, 0.0f, CSVReader.EventType.CARCRASH);
- e4.IdealViewingPos = new Vector3(0.0f, 50.0f, 0.0f);
- e4.TimestampEnd = 77.7;
- Assert.IsTrue(events[0].Equals(e1));
- Assert.IsTrue(events[1].Equals(e2));
- Assert.IsTrue(events[2].Equals(e3));
- Assert.IsTrue(events[3].Equals(e4));
- //Re-Read sensors and check if unchanged
- events = eventReader.ReadFile();
- Assert.AreEqual(0, events.Length, "instead of 0, Event file has " + events.Length + " new entries");
- }
- [Test]
- public void WrongFileTest()
- {
- SensorCSVReader sensorReaderErr = new SensorCSVReader("WerBinIch");
- EventCSVReader eventReaderErr = new EventCSVReader("WoBinIch");
- Assert.IsNull(sensorReaderErr.ReadFile());
- Assert.IsNull(eventReaderErr.ReadFile());
- }
- [TearDown]
- public void TearDown()
- {
- }
- }
- }
|