Exemplo n.º 1
0
        public void CalculateVelocity_ListOfTracksAlreadyOnOldTracks_VelocityIsCorrect(int x, int y, int alt, int time1, int time2, double velocity)
        {
            //Arrange
            var trackOne  = new Track("one", _withinOne, new DateTime(2000, 1, 1, 1, 1, time1));
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            var args = new EventTracks(trackList);

            //Act
            _filter.TracksFiltered += Raise.EventWith(args);

            //Arrange again
            trackOne  = new Track("one", new Point(_withinOne.X + x, _withinOne.Y + y, _withinOne.Altitude + alt), new DateTime(2000, 1, 1, 1, 1, time2));
            trackList = new List <ITrack>();
            trackList.Add(trackOne);
            args = new EventTracks(trackList);

            //Act again
            _filter.TracksFiltered += Raise.EventWith(args);

            //Assert
            Assert.That(_trackList.Count(), Is.EqualTo(1));
            Assert.That(_trackList.Contains(trackOne), Is.True);
            Assert.That(_trackList[0].Velocity, Is.EqualTo(velocity));
        }
Exemplo n.º 2
0
        public void RenderTracks_TwoTracks_DisplayFunctionsCalled()
        {
            //Arrange
            var trackOne  = new Track("one", _pointOne, new DateTime(2000, 1, 1, 1, 1, 5));
            var trackTwo  = new Track("two", _pointTwo, new DateTime(2000, 1, 1, 1, 1, 8));
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            var args = new EventTracks(trackList);

            //Act
            _update.TracksUpdated += Raise.EventWith(args);

            //Assert
            _display.Received(1).Write("***Tracks***");
            _display.Received(1).Write($"Tag: " + trackOne.Tag + " CurrentPosition: " + trackOne.Position.X + "mE," +
                                       trackOne.Position.Y +
                                       "mN Altitude: " + trackOne.Position.Altitude + "m Velocity: " +
                                       Math.Round(trackOne.Velocity, 2) + "m/s Course: " +
                                       Math.Round(trackOne.Course, 2) + "°");
            _display.Received(1).Write($"Tag: " + trackTwo.Tag + " CurrentPosition: " + trackTwo.Position.X + "mE," +
                                       trackTwo.Position.Y +
                                       "mN Altitude: " + trackTwo.Position.Altitude + "m Velocity: " +
                                       Math.Round(trackTwo.Velocity, 2) + "m/s Course: " +
                                       Math.Round(trackTwo.Course, 2) + "°");
        }
        public void DetectSeparation_TwoTracksNoLongerCausingSeparation_RemovedFromList(int x1, int y1, int alt1, bool separation1, int x2, int y2, int alt2, bool separation2)
        {
            //Arrange
            var trackOne  = new Track("one", _point, new DateTime(2000, 12, 31, 23, 59, 59));
            var trackTwo  = new Track("two", new Point(_point.X + x1, _point.Y + y1, _point.Altitude + alt1), new DateTime(2000, 12, 31, 23, 59, 59));
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            var args = new EventTracks(trackList);

            //Act
            _update.TracksUpdated += Raise.EventWith(args);

            //Assert
            Assert.That(_separationData.Any(), Is.EqualTo(separation1));
            Assert.That(_separationData.Count(), Is.EqualTo(1));

            //Re-Arrange
            trackOne  = new Track("one", _point, new DateTime(2000, 12, 31, 23, 59, 59));
            trackTwo  = new Track("two", new Point(_point.X + x2, _point.Y + y2, _point.Altitude + alt2), new DateTime(2000, 12, 31, 23, 59, 59));
            trackList = new List <ITrack>();
            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            args = new EventTracks(trackList);

            //Re-Act
            _update.TracksUpdated += Raise.EventWith(args);

            //Re-Assert
            Assert.That(_separationData.Any(), Is.EqualTo(separation2));
            Assert.That(_separationData.Count(), Is.EqualTo(0));
        }
Exemplo n.º 4
0
        public void CalculateCourse_ListOfTracksAlreadyOnOldTracks_CourseIsCorrect(int x, int y, int alt, double course)
        {
            //Arrange
            var trackOne  = new Track("one", _withinOne, DateTime.Now);
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            var args = new EventTracks(trackList);

            //Act
            _filter.TracksFiltered += Raise.EventWith(args);

            //Arrange again
            trackOne  = new Track("one", new Point(_withinOne.X + x, _withinOne.Y + y, _withinOne.Altitude + alt), DateTime.Now);
            trackList = new List <ITrack>();
            trackList.Add(trackOne);
            args = new EventTracks(trackList);

            //Act again
            _filter.TracksFiltered += Raise.EventWith(args);

            //Assert
            Assert.That(_trackList.Count(), Is.EqualTo(1));
            Assert.That(_trackList.Contains(trackOne), Is.True);
            Assert.That(_trackList[0].Course, Is.EqualTo(course));
        }
        private void DetectSeparations(object sender, EventTracks e)
        {
            var updatedSeparations = new List <ISeparation>();

            foreach (var trackOne in e.TrackData)
            {
                foreach (var trackTwo in e.TrackData)
                {
                    if (trackOne.Tag != trackTwo.Tag)
                    {
                        if (CalculateSeparation(trackOne.Position, trackTwo.Position))
                        {
                            var oldSeparations = updatedSeparations.FirstOrDefault(s => s.Tag1 == trackOne.Tag || s.Tag2 == trackOne.Tag);
                            if (oldSeparations == null)
                            {
                                updatedSeparations.Add(new Separation(trackOne.Tag, trackTwo.Tag, trackOne.Timestamp));
                            }
                        }
                    }
                }
            }

            foreach (var sep in updatedSeparations)
            {
                var oldSeparation = _oldSeparations.FirstOrDefault(s => s.Tag1 == sep.Tag1 && s.Tag2 == sep.Tag2);
                if (oldSeparation == null)
                {
                    _logger.Log(sep.Tag1 + ";" + sep.Tag2 + ";" + sep.TimeStamp);
                }
            }

            _oldSeparations = updatedSeparations;
            UpdatedSeparationEvent(new EventSeparation(updatedSeparations));
        }
Exemplo n.º 6
0
        private void RenderEnteredTracks(object sender, EventTracks e)
        {
            _display.Write("*TRACKS ENTERED AIRSPACE*\n");
            foreach (var track in e.Data)
            {
                var timer = new Timer();
                var str   = "Tag: " + track.Tag + ", Time: " + track.Timestamp.ToString("G");

                timer.Enabled  = true;
                timer.Interval = 5000;
                _display.Write(str);
            }
        }
        public void TracksEnterAirspace_ChecksWhenTrackEntersAirspace()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackInsideAirspace = new Track("TagOne", _trackEntersAirspace, DateTime.Now);

            data.Add(trackInsideAirspace);

            _updateModule.TracksUpdated += Raise.EventWith(args);

            Assert.That(_tracks.Contains(trackInsideAirspace));
        }
        public void CheckIfTrackleftAirspace()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackOutsideAirspace = new Track("TagOne", _trackLeftAirspace, DateTime.Now);

            data.Add(trackOutsideAirspace);

            _updateModule.TracksUpdated += Raise.EventWith(args);

            Assert.That(_tracks.Contains(trackOutsideAirspace), Is.EqualTo(false));
        }
Exemplo n.º 9
0
 //Renders the tracks
 private void RenderTracks(object sender, EventTracks e)
 {
     //Clears the console from history of events.
     _display.Clear();
     _display.Write("*TRACKS*");
     foreach (var track in e.Data)
     {
         var str = "Tag: " + track.Tag + " Current position: " + track.Position.X +
                   " east, " + track.Position.Y + " north, altitude: " + track.Position.Altitude +
                   "m, Velocity: " + track.Velocity + "m/s, Course: " + track.Course + " degree";
         _display.Write(str);
     }
 }
Exemplo n.º 10
0
 private void RenderTracks(object sender, EventTracks e)
 {
     _display.Write("***Tracks***");
     foreach (var track in e.TrackData)
     {
         var str = "Tag: " + track.Tag + " CurrentPosition: " + track.Position.X + "mE," +
                   track.Position.Y +
                   "mN Altitude: " + track.Position.Altitude + "m Velocity: " +
                   Math.Round(track.Velocity, 2) + "m/s Course: " +
                   Math.Round(track.Course, 2) + "°";
         _display.Write(str);
     }
 }
Exemplo n.º 11
0
        //Filter tracks - focuses only on tracks within the airspace
        //Ignores irrelevant airplanes
        private void FilterTracks(object sender, EventTracks e)
        {
            var filtered = new List <ITrack>();

            foreach (var track in e.Data)
            {
                if (_airspace.CheckIfWithinAirspace(track.Position))
                {
                    filtered.Add(track);
                }
            }

            NewFiltered(new EventTracks(filtered));
        }
Exemplo n.º 12
0
        private void FilterTracks(object sender, EventTracks e)
        {
            var filteredTracks = new List <ITrack>();

            foreach (var track in e.TrackData)
            {
                if (_airspace.CalculateWithinAirspace(track.Position))
                {
                    filteredTracks.Add(track);
                }
            }

            FilteredTrackEvent(new EventTracks(filteredTracks));
        }
Exemplo n.º 13
0
        public void SeparateTracks_LoggingTheSeparatedTracks()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackOneLog = new Track("TagOne", _trackOne, DateTime.Now);
            var trackTwoLog = new Track("TagTwo", _trackTwo, DateTime.Now);

            data.Add(trackOneLog);
            data.Add(trackTwoLog);

            _updateModule.TracksUpdated += Raise.EventWith(args);

            _log.Received().Logging("TagOne: TagOne; TagTwo: TagTwo; " + "Time: " + DateTime.Now);
        }
Exemplo n.º 14
0
        public void SeparateTracks_ChecksIfTracksAreTooCloseToEachOther_ContainsListOfSeparatingTracks()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackOne = new Track("TagOne", _trackOne, DateTime.Now);
            var trackTwo = new Track("TagTwo", _trackTwo, DateTime.Now);

            data.Add(trackOne);
            data.Add(trackTwo);

            _updateModule.TracksUpdated += Raise.EventWith(args);

            Assert.That(_collisions.Count(), Is.EqualTo(1));
            Assert.That(_collisions.Any(), Is.True);
        }
        public void DetectSeparation_TwoTracksCausingSeparation_LoggerUsed()
        {
            //Arrange
            var trackOne  = new Track("one", _point, new DateTime(2000, 12, 31, 23, 59, 59));
            var trackTwo  = new Track("two", _point, new DateTime(2000, 12, 31, 23, 59, 59));
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            var args = new EventTracks(trackList);

            //Act
            _update.TracksUpdated += Raise.EventWith(args);

            //Assert
            _logger.Received().Log("one;two;" + new DateTime(2000, 12, 31, 23, 59, 59));
        }
Exemplo n.º 16
0
        public void FilterTracks_ChecksIfTracksWithinAirspaceOrNot_ContainsListOfTracksWithinAirspace()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var insideAirspace  = new Track("TagOne", _insideAirspace, DateTime.Now);
            var outsideAirspace = new Track("TagTwo", _outsideAirspace, DateTime.Now);

            data.Add(insideAirspace);
            data.Add(outsideAirspace);

            _objectifyingModule.TracksObjectified += Raise.EventWith(args);

            //CheckWithInAirspace if True, it is correct, If false it is incorrect.
            Assert.That(_tracks.Contains(insideAirspace), Is.True);
            Assert.That(_tracks.Contains(outsideAirspace), Is.False);
        }
        public void TrackEnterAirspaceRender_ChecksIfTracksWithinAirspace_ReturnsMessage()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackOne = new Track("TagOne", _trackOne, DateTime.Now);
            var trackTwo = new Track("TagTwo", _trackTwo, DateTime.Now);

            data.Add(trackOne);
            data.Add(trackTwo);

            _tracksEnterAirspace.TracksEnteredAirspace += Raise.EventWith(args);

            _display.Received(1).Write("*TRACKS ENTERED AIRSPACE*\n");
            _display.Received(1).Write("Tag: " + trackOne.Tag + ", Time: " + DateTime.Now);
            _display.Received(1).Write("Tag: " + trackTwo.Tag + ", Time: " + DateTime.Now);
        }
Exemplo n.º 18
0
        public void FilterTracks_ListWithTracksBothWithinAirspaceAndOutsideAirspace_ListOfTracksOnlyWithinAirspace()
        {
            //Arrange
            var trackWithinAirspace  = new Track("one", _within, DateTime.Now);
            var trackOutsideAirspace = new Track("two", _outside, DateTime.Now);
            var trackList            = new List <ITrack>();

            trackList.Add(trackWithinAirspace);
            trackList.Add(trackOutsideAirspace);
            var args = new EventTracks(trackList);

            //Act
            _factory.TracksReady += Raise.EventWith(args);

            //Assert
            Assert.That(_trackList.Contains(trackWithinAirspace), Is.True);
            Assert.That(_trackList.Contains(trackOutsideAirspace), Is.False);
        }
        public void DetectSeparation_TwoTracksCausingSeparation_CalculateSeparationTrue(int x, int y, int alt, bool separation)
        {
            //Arrange
            var trackOne  = new Track("one", _point, new DateTime(2000, 12, 31, 23, 59, 59));
            var trackTwo  = new Track("two", new Point(_point.X + x, _point.Y + y, _point.Altitude + alt), new DateTime(2000, 12, 31, 23, 59, 59));
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            var args = new EventTracks(trackList);

            //Act
            _update.TracksUpdated += Raise.EventWith(args);

            //Assert
            Assert.That(_separationData.Any(), Is.EqualTo(separation));
            Assert.That(_separationData.Count(), Is.EqualTo(1));
        }
Exemplo n.º 20
0
        private void TrackLeftedAirspace(object sender, EventTracks e)
        {
            var leftTracks = new List <ITrack>();

            foreach (var track in e.Data)
            {
                //Check if within airspace, if within airspace add to list and printout on render
                //Else nothing.

                if (CheckIfTrackleftAirspace(track.Timestamp, track.Position))
                {
                    leftTracks.Add(track);
                }
            }
            // Update the list.
            _currentTracks = leftTracks;
            TracksleftAirspaceEvent(new EventTracks(leftTracks));
        }
Exemplo n.º 21
0
        private void UpdateTracks(object sender, EventTracks e)
        {
            var updatedTracks = new List <ITrack>();

            foreach (var track in e.TrackData)
            {
                var oldTrack = _oldTracks.FirstOrDefault(t => t.Tag == track.Tag);
                if (oldTrack != null)
                {
                    track.Course   = CalculateCourse(oldTrack.Position, track.Position);
                    track.Velocity = CalculateVelocity(oldTrack.Position, track.Position, oldTrack.Timestamp, track.Timestamp);
                }
                updatedTracks.Add(track);
            }

            _oldTracks = updatedTracks;
            UpdatedTrackEvent(new EventTracks(updatedTracks));
        }
Exemplo n.º 22
0
        public void UpdateTracks_ListOfTracksNotOnOldTracks_ListAdded()
        {
            //Arrange
            var trackOne  = new Track("one", _withinOne, DateTime.Now);
            var trackTwo  = new Track("two", _withinTwo, DateTime.Now);
            var trackList = new List <ITrack>();

            trackList.Add(trackOne);
            trackList.Add(trackTwo);
            var args = new EventTracks(trackList);

            //Act
            _filter.TracksFiltered += Raise.EventWith(args);

            //Assert
            Assert.That(_trackList.Count(), Is.EqualTo(2));
            Assert.That(_trackList.Contains(trackOne));
            Assert.That(_trackList.Contains(trackTwo));
        }
Exemplo n.º 23
0
        //Updates the filtered tracks and calculates course & velocity
        private void UpdateTracks(object sender, EventTracks e)
        {
            var updatedTracks = new List <ITrack>();

            foreach (var filtered in e.Data)
            {
                //If filtered.tag is on _oldtracks, update course and velocity
                //If not, add filtered
                var oldTracks = _oldTracks.FirstOrDefault(t => t.Tag == filtered.Tag);

                if (oldTracks != null)
                {
                    filtered.Course   = CalculateCourse(oldTracks.Position, filtered.Position);
                    filtered.Velocity = CalculateVelocity(oldTracks.Position, filtered.Position,
                                                          oldTracks.Timestamp, filtered.Timestamp);
                }

                updatedTracks.Add(filtered);
            }
            _oldTracks = updatedTracks;
            UpdatedTracksEvent(new EventTracks(updatedTracks));
        }
Exemplo n.º 24
0
        private void SeparationTracks(object sender, EventTracks e)
        {
            var updatedSeparationsTracks = new List <ICollision>();

            foreach (var separationTrack in e.Data)
            {
                foreach (var separationTrackTwo in e.Data)
                {
                    //If conflict occurs, do calculate, change positions from old to a new
                    //update it.
                    if (separationTrack.Tag != separationTrackTwo.Tag)
                    {
                        if (CalculateSeparationTracks(separationTrack.Position, separationTrackTwo.Position))
                        {
                            var oldSeparationTrack = updatedSeparationsTracks.FirstOrDefault(t =>
                                                                                             t.TagOne == separationTrack.Tag || t.TagTwo == separationTrack.Tag);
                            if (oldSeparationTrack == null)
                            {
                                updatedSeparationsTracks.Add(new Collision(separationTrack.Tag, separationTrackTwo.Tag,
                                                                           separationTrack.Timestamp));
                            }
                        }
                    }
                }
            }

            foreach (var separation in updatedSeparationsTracks)
            {
                var oldSeparationsTracks = _oldSeparationsTrack.FirstOrDefault(t =>
                                                                               t.TagOne == separation.TagOne && t.TagTwo == separation.TagTwo);
                if (oldSeparationsTracks == null)
                {
                    _log.Logging("TagOne: " + separation.TagOne + ";" + " TagTwo: " + separation.TagTwo + ";" + " Time: " + separation.Timestamp);
                }
            }

            _oldSeparationsTrack = updatedSeparationsTracks;
            UpdatedSeparationsTracksEvent(new EventSeparations(updatedSeparationsTracks));
        }
Exemplo n.º 25
0
        public void UpdateModule_UpdateListOfTracks()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var pointA = new Track("Tag1", _insideAirspacePointA, DateTime.Now);
            var pointB = new Track("Tag2", _insideAirspacePointB, DateTime.Now);
            var pointC = new Track("Tag3", _insideAirspacePointC, DateTime.Now);
            var pointD = new Track("Tag4", _insideAirspacePointD, DateTime.Now);

            data.Add(pointA);
            data.Add(pointB);
            data.Add(pointC);
            data.Add(pointD);

            _filterModule.TracksFiltered += Raise.EventWith(args);

            Assert.That(_tracks.Count(), Is.EqualTo(4));
            Assert.That(_tracks.Contains(pointA));
            Assert.That(_tracks.Contains(pointB));
            Assert.That(_tracks.Contains(pointC));
            Assert.That(_tracks.Contains(pointD));
        }
Exemplo n.º 26
0
        public void TrackRender_RenderTheTracksOnDisplay()
        {
            var data = new List <ITrack>();
            var args = new EventTracks(data);

            var trackOne = new Track("TagOne", _trackOne, DateTime.Now);
            var trackTwo = new Track("TagTwo", _trackTwo, DateTime.Now);

            data.Add(trackOne);
            data.Add(trackTwo);

            _updateModule.TracksUpdated += Raise.EventWith(args);

            _display.Received(1).Clear();
            _display.Received(1).Write("*TRACKS*\n");
            _display.Received(1).Write("Tag: " + trackOne.Tag + " Current position: " + trackOne.Position.X +
                                       " east, " + trackOne.Position.Y + " north, altitude: " + trackOne.Position.Altitude +
                                       "m, Velocity: " + trackOne.Velocity + "m/s, Course: " + trackOne.Course + " degree");

            _display.Received(1).Write("Tag: " + trackTwo.Tag + " Current position: " + trackTwo.Position.X +
                                       " east, " + trackTwo.Position.Y + " north, altitude: " + trackTwo.Position.Altitude +
                                       "m, Velocity: " + trackTwo.Velocity + "m/s, Course: " + trackTwo.Course + " degree");
        }
Exemplo n.º 27
0
 protected virtual void FilteredTrackEvent(EventTracks e)
 {
     TracksFiltered?.Invoke(this, e);
 }
Exemplo n.º 28
0
 protected virtual void TracksleftAirspaceEvent(EventTracks e)
 {
     TracksleftAirspace?.Invoke(this, e);
 }
Exemplo n.º 29
0
 protected virtual void NewFiltered(EventTracks e)
 {
     TracksFiltered?.Invoke(this, e);
 }
Exemplo n.º 30
0
 protected virtual void UpdatedTrackEvent(EventTracks e)
 {
     TracksUpdated?.Invoke(this, e);
 }