public void event_fired_on_planeDetector_from_decoder() { fd1.SetFlightData(100000000, 100000000, 0, new DateTime()); fd2.SetFlightData(50000, 50000, 5000, new DateTime()); _planesTestData.Add(fd1); _planesTestData.Add(fd2); _fakeDecoder.PlaneDecodedEvent += Raise.EventWith(new PlaneDecodedEventArgs { Planes = _planesTestData }); Assert.That(_receivedEventArgs, Is.Not.Null); }
[TestCase(-10, -5, 5)] // Coordinates below zero public void VerticalDistance(int zCoordinate1, int zCoordinate2, double result) { FlightData fd1 = new FlightData("1"); FlightData fd2 = new FlightData("2"); fd1.SetFlightData(0, 0, zCoordinate1, new DateTime()); fd2.SetFlightData(0, 0, zCoordinate2, new DateTime()); Assert.That(Calculator.VerticalDistance(fd1, fd2), Is.EqualTo(result).Within(0.1)); }
[TestCase(-10, -5, -10, -5, 7)] // Coordinates below zero public void HorizontalDistance(int xCoordinate1, int xCoordinate2, int yCoordinate1, int yCoordinate2, double result) { FlightData fd1 = new FlightData("1"); FlightData fd2 = new FlightData("2"); fd1.SetFlightData(xCoordinate1, yCoordinate1, 0, new DateTime()); fd2.SetFlightData(xCoordinate2, yCoordinate2, 0, new DateTime()); Assert.That(Calculator.HorizontalDistance(fd1, fd2), Is.EqualTo(result).Within(0.1)); }
public void WriteLine_Called_Amount_Of_Times() { List <FlightData> list = new List <FlightData>(); FlightData fd1 = new FlightData("123ABC"); FlightData fd2 = new FlightData("ABC123"); fd1.SetFlightData(123, 456, 789, DateTime.Now); fd2.SetFlightData(123, 456, 789, DateTime.Now); list.Add(fd1); list.Add(fd2); Uut.DisplayData(list); CwFake.Received(4).WriteLine(""); }
public void PlaneDetectorEvent_FlightDataController_ListController_Called() { FlightData F2 = new FlightData("2"); FlightData F3 = new FlightData("3"); F2.SetFlightData(8000, 8000, 8000, new DateTime()); F3.SetFlightData(8000, 8000, 8000, new DateTime()); _testPlanes.Add(F2); _testPlanes.Add(F3); _uut.ListController(new object(), new PlaneDetectorEventArgs() { PlanesInAirspace = _testPlanes }); _fakeRenderer.Received().DisplayData(Arg.Any <List <FlightData> >()); }
public void CollisionDetected_LoggerCalled() { FlightData F1 = new FlightData("1"); FlightData F2 = new FlightData("2"); F1.SetFlightData(8000, 8000, 8000, new DateTime()); F2.SetFlightData(8000, 8000, 8000, new DateTime()); _testPlanes.Add(F1); _testPlanes.Add(F2); _uut.OnPlaneDetectorEvent(new object(), new PlaneDetectorEventArgs() { PlanesInAirspace = _testPlanes }); _fakeLogger.Received().Log(Arg.Is <FlightData>(F1), Arg.Is <FlightData>(F2)); }
public void CalculateVelocitySameTimeStampExceptionThrown() { FlightData fd1 = new FlightData("1"); FlightData fd2 = new FlightData("2"); fd1.SetFlightData(0, 0, 0, new DateTime(2019, 10, 31, 13, 45, 0)); fd2.SetFlightData(0, 0, 0, new DateTime(2019, 10, 31, 13, 45, 0)); List <FlightData> list1 = new List <FlightData>(); List <FlightData> list2 = new List <FlightData>(); list1.Add(fd1); list2.Add(fd2); List <FlightData> resultList = new List <FlightData>(); Assert.Throws <ArgumentException>(() => Calculator.CalculateVelocity(list1, list2)); // Should throw exception - devision by 0 }
[TestCase(0, -1, 0, 100, 359.5)] // 4th quadrant - Close to 0/360 degrees public void Calculate_Course(int xCoordinate1, int xCoordinate2, int yCoordinate1, int yCoordinate2, double result) { FlightData fd1 = new FlightData("1"); FlightData fd2 = new FlightData("2"); fd1.SetFlightData(xCoordinate1, yCoordinate1, 0, new DateTime()); fd2.SetFlightData(xCoordinate2, yCoordinate2, 0, new DateTime()); List <FlightData> list1 = new List <FlightData>(); List <FlightData> list2 = new List <FlightData>(); list1.Add(fd1); list2.Add(fd2); List <FlightData> resultList = new List <FlightData>(); resultList = Calculator.CalculateCompassCourse(list1, list2); Assert.That(resultList[0].CompassCourse, Is.EqualTo(result).Within(0.4)); }
[TestCase(-2, -1, -2, -2, 0, 2, 0.5)] // negative values public void CalculateVelocity(int xCoordinate1, int xCoordinate2, int yCoordinate1, int yCoordinate2, int sec1, int sec2, double result) { FlightData fd1 = new FlightData("1"); FlightData fd2 = new FlightData("2"); fd1.SetFlightData(xCoordinate1, yCoordinate1, 0, new DateTime(2019, 10, 31, 13, 45, sec1)); fd2.SetFlightData(xCoordinate2, yCoordinate2, 0, new DateTime(2019, 10, 31, 13, 45, sec2)); List <FlightData> list1 = new List <FlightData>(); List <FlightData> list2 = new List <FlightData>(); list1.Add(fd1); list2.Add(fd2); List <FlightData> resultList = new List <FlightData>(); resultList = Calculator.CalculateVelocity(list1, list2); Assert.That(resultList[0].Velocity, Is.EqualTo(result).Within(0.1)); }
public void Setup() { _fakeAirSpacePlaneDetector = Substitute.For <IAirSpacePlaneDetector>(); _fakeRenderer = Substitute.For <IRenderer>(); _uut = new FlightDataController(_fakeAirSpacePlaneDetector); _uut.render = _fakeRenderer; _testPlanes = new List <FlightData>(); // ListController Called ONCE so that flightDataList.Count > 0; // Otherwise the Calculator and Renderer wont be called FlightData F1 = new FlightData("1"); F1.SetFlightData(8000, 8000, 8000, new DateTime()); _testPlanes.Add(F1); _uut.ListController(new object(), new PlaneDetectorEventArgs() { PlanesInAirspace = _testPlanes }); }
[TestCase(4699, 5000, 5000, 5000, 7000, 6000)] // 301 horizontal y-distance between two planes public void PlaneDetectorEvent_HorizontalCases_LoggerNotCalled(int X1, int X2, int Y1, int Y2, int Z1, int Z2) { FlightData F1 = new FlightData("1"); FlightData F2 = new FlightData("2"); F1.SetFlightData(X1, Y1, Z1, new DateTime()); F2.SetFlightData(X2, Y2, Z2, new DateTime()); _testPlanes.Add(F1); _testPlanes.Add(F2); _fakeAirspacePlaneDetector.AirplaneDetected += Raise.EventWith <PlaneDetectorEventArgs>( this, new PlaneDetectorEventArgs() { PlanesInAirspace = _testPlanes }); _fakeLogger.DidNotReceive().Log(Arg.Any <FlightData>(), Arg.Any <FlightData>()); }
[TestCase(5000, 5000, 5000, 5000, 8000, 3002)] // 4998 vertical z-distance between two planes public void CollisionDetected_VerticalCases_LoggerCalled(int X1, int X2, int Y1, int Y2, int Z1, int Z2) { FlightData F1 = new FlightData("1"); FlightData F2 = new FlightData("2"); bool wasCalled = false; F1.SetFlightData(X1, Y1, Z1, new DateTime()); F2.SetFlightData(X2, Y2, Z2, new DateTime()); _testPlanes.Add(F1); _testPlanes.Add(F2); _fakeAirspacePlaneDetector.AirplaneDetected += Raise.EventWith <PlaneDetectorEventArgs>( this, new PlaneDetectorEventArgs() { PlanesInAirspace = _testPlanes }); _fakeLogger.Received().Log(Arg.Is <FlightData>(F1), Arg.Is <FlightData>(F2)); }
public void Calculate_Course_Second_List_Longer() { FlightData fd1_1 = new FlightData("1_1"); FlightData fd2_1 = new FlightData("1_2"); FlightData fd2_2 = new FlightData("2_1"); fd1_1.SetFlightData(0, 0, 0, new DateTime()); fd2_1.SetFlightData(20, 20, 0, new DateTime()); fd2_2.SetFlightData(-20, -20, 0, new DateTime()); List <FlightData> list1 = new List <FlightData>(); List <FlightData> list2 = new List <FlightData>(); list1.Add(fd1_1); list2.Add(fd2_1); list2.Add(fd2_2); List <FlightData> resultList = new List <FlightData>(); resultList = Calculator.CalculateCompassCourse(list1, list2); Assert.That(resultList[0].CompassCourse, Is.EqualTo(45)); }