public void CollisionWarning(IDictionary <string, Aircraft> aircrafts) { for (int i = 0; i < aircrafts.Count; i++) { for (int j = i + 1; j < aircrafts.Count; j++) { var ac1 = aircrafts.Values.ElementAt(i); var ac2 = aircrafts.Values.ElementAt(j); if (IsColliding(ac1, ac2)) { if (!_collidingAircrafts.Any(x => x.Item1.Tag == ac1.Tag && x.Item2.Tag == ac2.Tag)) { //This raises the collision event - but only the first time var tempTuple = new Tuple <Aircraft, Aircraft, SeparationEventArgs>(ac1, ac2, new SeparationEventArgs(ac1, ac2)); _collidingAircrafts.Add(tempTuple); SeparationEvent?.Invoke(this, tempTuple.Item3); } } else { if (_collidingAircrafts.Any(x => x.Item1.Tag == ac1.Tag && x.Item2.Tag == ac2.Tag)) { //This removes the collision event. var tempTuple = _collidingAircrafts.Find(x => x.Item1.Tag == ac1.Tag && x.Item2.Tag == ac2.Tag); SeparationAvoidedEvent?.Invoke(this, tempTuple.Item3); _collidingAircrafts.Remove(tempTuple); } } } } }
public void Setup() { _uut = new SeparationEvent(); _calcDistance = Substitute.For <ICalcDistance>(); _track1 = Substitute.For <ITracks>(); _track2 = Substitute.For <ITracks>(); }
[Test] //to make sure we have not hardcoded some value public void Constructor_WhenCalledWithValidParams_SetsTimeStampObjectCase2() { var yesterday = DateTime.Now.AddDays(-1); var separationEvent = new SeparationEvent("123456", "654321", yesterday); Assert.That(separationEvent.Timestamp, Is.EqualTo(yesterday)); }
public void Constructor_WhenCalledWithValidParams_SetsTimeStampObjectCase1() { var now = DateTime.Now; var separationEvent = new SeparationEvent("123456", "654321", now); Assert.That(separationEvent.Timestamp, Is.EqualTo(now)); }
public void DeleteSeperationEvent(SeparationEvent e) { var tempSepEvent = Get(e); if (tempSepEvent == null) { return; } _separations.Remove(tempSepEvent); }
public void AddSeperationEvent(SeparationEvent e) { var tempSepEvent1 = Get(e.Tag1, e.Tag2); var tempSepEvent2 = Get(e.Tag2, e.Tag1); if (tempSepEvent1 == null && tempSepEvent2 == null) { _separations.Add(e); } }
public void ToString_WhenCalled_ReturnsAStringInTheCorrectFormat() { var tag1 = "tag111"; var tag2 = "tag222"; var dateTime = DateTime.Now; var separationEvent = new SeparationEvent(tag1, tag2, dateTime); var expectedResult = $"{tag1} <---> {tag2} @ {dateTime:dd-MM-yyyy HH:mm:ss}"; var result = separationEvent.ToString(); Assert.That(result, Is.EqualTo(expectedResult)); }
public void DetectCollision(List <Plane> planes) { //We don't want to deal with empty lists or less than 2 planes if (planes == null || planes.Count < 2) { return; } //Check if any new collisions have occured (The dreaded n^2 loop) for (int i = 0; i < planes.Count - 1; ++i) { for (int j = i + 1; j < planes.Count; ++j) { if (planes[j].Speed == 0) { break; //Break in case of new plane } int differenceInAltitude = planes[j].Altitude - planes[i].Altitude; if (differenceInAltitude < 300 && differenceInAltitude > -300) { //Planes are within 300 meters in altitude, otherwise just ignore double distance = CalculateDistance(planes[i], planes[j]); if (distance < 5000) { //Verify that collision is not already added to list if (Collisions.Contains(Tuple.Create(planes[i], planes[j]))) { break; } Collisions.Add(Tuple.Create(planes[i], planes[j])); SeparationEvent?.Invoke(this, new CollisionEventArgs(planes[i], planes[j])); } } } } }
public void MonitorSeparation(Dictionary <string, List <Track> > tracks) { for (int i = 0; i < tracks.Count; i++) { for (int j = i + 1; j < tracks.Count - i; j++) { if (tracks.ElementAt(i).Value.Count > 1 && tracks.ElementAt(j).Value.Count > 1 && tracks.ElementAt(i + j).Value.Count > 1) { var needSeparation = CheckSeparation(tracks.ElementAt(i).Value[1].Position.X, tracks.ElementAt(i).Value[1].Position.Y, tracks.ElementAt(i + j).Value[1].Position.X, tracks.ElementAt(i + j).Value[1].Position.Y, tracks.ElementAt(i).Value[1].Altitude, tracks.ElementAt(i + j).Value[1].Altitude); if (needSeparation) { SeparationEvent?.Invoke(this, new SeparationEventArgs() { Track1 = tracks.ElementAt(i).Value[1].Tag, TimeOfOccurence = tracks.ElementAt(i).Value[1].TimeStamp, Track2 = tracks.ElementAt(j).Value[1].Tag }); } } } } }
static void Main(string[] args) { //Tilføjet printer til output IOutput Output = new Output(); Print Printer; IMonitors monitor = new Monitor(); ITransponderReceiver transponderDataReceiver = TransponderReceiverFactory.CreateTransponderDataReceiver(); IUpdate update; ICalcVelocity calcVelocity = new CalcVelocity();; ICalcCourse calcCourse = new CalcCourse(); ILog logger = new Logger(); ISeparation separation = new SeparationEvent(); ICalcDistance calcDistance = new CalcDistance(); var decoder = new DecodingWithEvent(transponderDataReceiver); //Kaldet bliver lagt her til eventet. Som en slags subscriber. update = new Update(decoder); //decoder.TrackDataReady += (o, trackArgs) => Printer = new Print(update,calculator,monitor,Output,trackArgs.TrackData); decoder.TrackDataReadyForCalculation += (o, trackArgs) => Printer = new Print(update, calcDistance, calcCourse, calcVelocity, logger, separation, monitor, Output, trackArgs.TrackData); System.Console.ReadLine(); }
[TestCase("222222", "000000")] //to make sure we have not hardcoded some value public void Constructor_WhenCalledWithValidParams_SetsTag2Property(string tag1, string tag2) { var separationEvent = new SeparationEvent(tag1, tag2, DateTime.Now); Assert.That(separationEvent.Tag2, Is.EqualTo(tag2)); }
protected virtual void NewSeparationEvent(SeparationEvent e) { SeparationEvent?.Invoke(this, e); }
public SeparationEvent Get(SeparationEvent e) { return(_separations.Find(i => i.Tag1 == e.Tag1 && i.Tag2 == e.Tag2)); }