Exemplo n.º 1
0
        public void FileLogger_Setup()
        {
            _uutLogger = new FileLogger();
            _logFile   = "../../TestLog.txt";

            _track1 = FakeTrackFactory.GetTrackWithTag("Tag1", 1, 2, 3);
            _track2 = FakeTrackFactory.GetTrackWithTag("Tag2", 4, 5, 6);
        }
        public void Calculate_AngleCorrect_ReturnsRightAngle(int x1, int y1, int x2, int y2, int angleBetween)
        {
            var firstTrack  = FakeTrackFactory.GetTrack(x1, y1, 0);
            var secondTrack = FakeTrackFactory.GetTrack(x2, y2, 0);

            var result = _uutTrackCourseCalculator.Calculate(firstTrack, secondTrack);

            Assert.That(result, Is.EqualTo(angleBetween).Within(1).Percent);
        }
Exemplo n.º 3
0
        public void Traffic_Controller_Console_Display_Test(string tag, int x, int y, int z)
        {
            _tracks.Add(FakeTrackFactory.GetTrackWithTag(tag, x, y, z));
            _uutTrafficController.DisplayTracks(_tracks);

            string compare = "Tag: " + tag + "Pos X: " + x + "Pos Y: " + y;

            StringAssert.Contains(compare, _uutTrafficController.Output);
        }
Exemplo n.º 4
0
        public void Calculate_CalculateRightTrackDistance_ReturnIsCorrect(int x1, int y1, int x2, int y2, int expected)
        {
            var firstTrack  = FakeTrackFactory.GetTrack(x1, y1, 100);
            var secondTrack = FakeTrackFactory.GetTrack(x2, y2, 100);

            var result = _uutTrackHorizontalDistanceCalculator.Calculate(firstTrack, secondTrack);

            Assert.That(result.Equals(expected));
        }
Exemplo n.º 5
0
        public void ConditionBetween_ConditionNotFoundAnyCoordinate_ReturnsFalse(int horizontalRestriction, int xTrack1, int yTrack1, int xTrack2, int yTrack2)
        {
            _uutTrackHorizontalDistanceCondition.HorizontalDistance = horizontalRestriction;
            ITrack track1 = FakeTrackFactory.GetTrack(xTrack1, yTrack1, 1000);
            ITrack track2 = FakeTrackFactory.GetTrack(xTrack2, yTrack2, 1000);

            var result = _uutTrackHorizontalDistanceCondition.ConditionBetween(track1, track2);

            Assert.That(result == false);
        }
        public void ConditionBetween_ConditionNotFound_ReturnsFalse(int altitudeRestriction, int altitudeTrack1, int altitudeTrack2)
        {
            _uuTrackAltitudeCondition.AltitudeRestriction = altitudeRestriction;
            ITrack track1 = FakeTrackFactory.GetTrack(1000, 1000, altitudeTrack1);
            ITrack track2 = FakeTrackFactory.GetTrack(2000, 2000, altitudeTrack2);

            var result = _uuTrackAltitudeCondition.ConditionBetween(track1, track2);

            Assert.That(result == false);
        }
        public void Calculate_CalculateRightTrackDistance_ReturnIsCorrect()
        {
            var firstTrack  = FakeTrackFactory.GetTrackWithTime("20190101000000000", 100, 100, 100);
            var secondTrack = FakeTrackFactory.GetTrackWithTime("20190101000500000", 100, 100, 100);//5 minutes after the last

            _fakeTrackHorizontalDistanceCalculator.Calculate(Arg.Any <ITrack>(), Arg.Any <ITrack>()).Returns(300);


            var result = _uutTrackSpeedCalculator.Calculate(firstTrack, secondTrack);

            Assert.That(result, Is.EqualTo(1));
        }
Exemplo n.º 8
0
        public static List <ITrack> GetMultipleTracksWithTags(int number)
        {
            var rand   = new Random();
            var tracks = new List <ITrack>();

            for (int i = 0; i < number; i++)
            {
                var x = rand.Next(1, 100);
                var y = rand.Next(1, 100);
                var z = rand.Next(1, 100);


                tracks.Add(FakeTrackFactory.GetTrackWithTag("Track " + i + 1, x, y, z));
            }

            return(tracks);
        }
        public void DetectCondition_ConditionNotFound_EventHandlerNotInvoked()
        {
            bool       invoked     = false;
            ITrack     firstTrack  = FakeTrackFactory.GetTrack(1000, 1000, 1000);
            ITrack     secondTrack = FakeTrackFactory.GetTrack(1100, 1100, 1000);
            ITrackable airspace    = FakeAirspaceGenerator.GetAirspace(0, 0, 0);

            airspace.Trackables = new List <ITrack>()
            {
                firstTrack, secondTrack
            };
            _fakeCondition.ConditionBetween(Arg.Any <ITrack>(), Arg.Any <ITrack>()).Returns(false);
            _uutConditionDetector.ConditionsHandler += (s, e) => invoked = true;

            _uutConditionDetector.DetectCondition(airspace);

            Assert.That(invoked == false);
        }
        public void DetectCondition_ConditionFound_SecondConditionCorrect()
        {
            ConditionEventArgs eventArgsReceived = null;
            ITrack             firstTrack        = FakeTrackFactory.GetTrack(1000, 1000, 1000);
            ITrack             secondTrack       = FakeTrackFactory.GetTrack(1100, 1100, 1000);
            ITrackable         airspace          = FakeAirspaceGenerator.GetAirspace(0, 0, 0);

            airspace.Trackables = new List <ITrack>()
            {
                firstTrack, secondTrack
            };
            _fakeCondition.ConditionBetween(Arg.Any <ITrack>(), Arg.Any <ITrack>()).Returns(true);
            _uutConditionDetector.ConditionsHandler += (s, e) => eventArgsReceived = e;

            _uutConditionDetector.DetectCondition(airspace);

            Assert.That(eventArgsReceived.SecondConditionHolder, Is.EqualTo(secondTrack));
        }
Exemplo n.º 11
0
        public void Traffic_Controller_Console_Display_Test_Condition(string tag1, int x1, int y1, int z1, string tag2, int x2, int y2, int z2)
        {
            var track1 = FakeTrackFactory.GetTrackWithTag(tag1, x1, y1, z1);
            var track2 = FakeTrackFactory.GetTrackWithTag(tag2, x2, y2, z2);

            _tracks.Add(track1);
            _tracks.Add(track2);

            var condition = new ConditionEventArgs(track1, track2);

            _condtions.Add(condition);



            _uutTrafficController.DisplayConditions(_condtions);

            var compare = "Condition detected between " + track1.Tag + " & " + track2.Tag;

            StringAssert.Contains(compare, _uutTrafficController.Condition);
        }
        public void DetectCondition_MultipleConditions_EventHandlerInvokedCorrect(int numConditions)
        {
            int        timesInvoked    = 0;
            ITrack     trackInAirspace = FakeTrackFactory.GetTrack(1000, 1000, 1000);
            ITrackable airspace        = FakeAirspaceGenerator.GetAirspace(0, 0, 0);

            airspace.Trackables.Add(trackInAirspace); //There must be one track always
            for (int i = 0; i < numConditions; i++)
            {
                airspace.Trackables.Add(trackInAirspace);
            }
            //Because each element in the airspace is compared to each other:
            int expectedVisitations = numConditions * airspace.Trackables.Count / 2;

            _fakeCondition.ConditionBetween(Arg.Any <ITrack>(), Arg.Any <ITrack>()).Returns(true);
            _uutConditionDetector.ConditionsHandler += (s, e) => ++ timesInvoked;

            _uutConditionDetector.DetectCondition(airspace);

            Assert.That(timesInvoked, Is.EqualTo(expectedVisitations));
        }
Exemplo n.º 13
0
        public void UpdateTrackDisplayTest(int num)
        {
            _logger = new FileLogger();

            _trafficController = Substitute.For <ConsoleAirTrafficController>();

            _uutOutputter.Logger = _logger;
            _logger.PathToFile   = _logFile;

            _uutOutputter.TrafficController = _trafficController;

            _tracks = FakeTrackFactory.GetMultipleTracksWithTags(num);

            _airspace.Trackables = _tracks;


            _uutOutputter.UpdateTrackDisplay(_airspace);


            _uutOutputter.TrafficController.Received(1).DisplayTracks(_tracks);
        }
Exemplo n.º 14
0
        public static List <ConditionEventArgs> CreateConditionList(int numberOfConditions)
        {
            var rand       = new Random();
            var conditions = new List <ConditionEventArgs>();

            for (int i = 0; i < numberOfConditions; i++)
            {
                var x = rand.Next(1, 100);
                var y = rand.Next(1, 100);
                var z = rand.Next(1, 100);


                var track1 = FakeTrackFactory.GetTrackWithTag("Track1," + i, x, y, z);
                var track2 = FakeTrackFactory.GetTrackWithTag("Track2," + i, x + 4, y + 5, z - 7);

                var cond = new ConditionEventArgs(track1, track2);

                conditions.Add(cond);
            }

            return(conditions);
        }