예제 #1
0
        public void WhenMainRouteWptDoesNotExistShouldRecordFailure()
        {
            // Arrange
            var p1 = new Waypoint("P1", 0.0, 0.0);
            var p2 = new Waypoint("P2", 0.0, 2.0);

            var wptList = new WaypointList();

            var route = new Route();

            route.AddLastWaypoint(p1);
            route.AddLastWaypoint(p2, "DCT");
            var nodes = new TrackNodes("A", "NATA", route, new List <WptPair>());

            var recorder = new StatusRecorder();

            var adder = new TrackAdder(
                wptList,
                wptList.GetEditor(),
                recorder,
                TrackType.Nats);

            // Act
            adder.AddToWaypointList(new[] { nodes });

            // Assert
            Assert.AreEqual(1, recorder.Records.Count);
        }
예제 #2
0
        private void ValidateFirstWpt(int index)
        {
            if (index == -1)
            {
                if (TryParseCoord(routeInput[0]))
                {
                    return;
                }

                throw new ArgumentException($"{routeInput[0]} is not a valid coordinate.");
            }

            if (!wptList.WaypointExists(index))
            {
                throw new ArgumentException("Wrong first waypoint index.");
            }

            var wpt = wptList[index];

            if (routeInput[0] != wpt.ID)
            {
                throw new ArgumentException(
                          "The first waypoint of the route does not match the " +
                          "specified index in WptList.");
            }

            lastWpt = index;
            rte.AddLastWaypoint(wpt);
        }
예제 #3
0
        private Route DirectRoute()
        {
            var route = new Route();

            route.AddLastWaypoint(origRwyWpt);
            route.AddLastWaypoint(destRwyWpt, "DCT");
            return(route);
        }
예제 #4
0
        private Route GetRoute1()
        {
            var route = new Route();

            route.AddLastWaypoint(new Waypoint("Y", 0.0, 1.0));
            route.AddLastWaypoint(new Waypoint("Z", 0.0, 3.0), "1");

            return(route);
        }
예제 #5
0
        private Route GetRoute2()
        {
            var route = new Route();

            route.AddLastWaypoint(new Waypoint("2", 0.0, 0.0));
            route.AddLastWaypoint(new Waypoint("4", 0.0, 0.0), "C");
            route.AddLastWaypoint(new Waypoint("3", 0.0, 0.0), "D");

            return(route);
        }
예제 #6
0
        private Route GetRoute1()
        {
            var route = new Route();

            route.AddLastWaypoint(new Waypoint("1", 0.0, 0.0));
            route.AddLastWaypoint(new Waypoint("2", 0.0, 0.0), "A");
            route.AddLastWaypoint(new Waypoint("3", 0.0, 0.0), "B");

            return(route);
        }
예제 #7
0
        public void GetTotalDistanceCustomDistance()
        {
            var x = new Waypoint("X", 0.0, 0.0);
            var y = new Waypoint("Y", 0.0, 1.0);
            var z = new Waypoint("Z", 1.0, 3.0);

            var route = new Route();

            route.AddLastWaypoint(x);
            route.AddLastWaypoint(y, "0", 100.0);
            route.AddLastWaypoint(z, "1", 200.0);

            Assert.AreEqual(300.0, route.TotalDistance(), 1E-8);
        }
예제 #8
0
        /// <exception cref="ArgumentException"></exception>
        public static Route ToRoute(this IEnumerable <ICoordinate> coordinates)
        {
            var items = coordinates.ToList();

            if (items.Count < 2)
            {
                throw new ArgumentException();
            }

            var result = new Route();

            foreach (var i in items)
            {
                double lat = i.Lat;
                double lon = i.Lon;

                string latLonTxt =
                    Format5Letter.ToString(lat, lon) ??
                    FormatDecimal.ToString(lat, lon);

                var wpt = new Waypoint(latLonTxt, lat, lon);
                result.AddLastWaypoint(wpt, "DCT");
            }

            return(result);
        }
예제 #9
0
        public void GetTotalDistanceTest()
        {
            var x = new Waypoint("X", 0.0, 0.0);
            var y = new Waypoint("Y", 0.0, 1.0);
            var z = new Waypoint("Z", 1.0, 3.0);

            var route = new Route();

            route.AddLastWaypoint(x);
            route.AddLastWaypoint(y, "0");
            route.AddLastWaypoint(z, "1");

            var expectedDis = x.Distance(y) + y.Distance(z);

            Assert.AreEqual(expectedDis, route.TotalDistance());
        }
예제 #10
0
        public void AddsMainRouteCorrectly()
        {
            // Arrange
            var p1 = new Waypoint("P1", 0.0, 0.0);
            var p2 = new Waypoint("P2", 0.0, 2.0);
            var p3 = new Waypoint("P3", 0.0, 4.0);

            var wptList = new WaypointList();

            wptList.AddWaypoint(p1);
            wptList.AddWaypoint(p2);
            wptList.AddWaypoint(p3);

            var route = new Route();

            route.AddLastWaypoint(p1);
            route.AddLastWaypoint(p2, "DCT");
            route.AddLastWaypoint(p3, "DCT");
            var nodes = new TrackNodes("A", "NATA", route, new WptPair[0]);

            var adder = new TrackAdder(
                wptList,
                wptList.GetEditor(),
                new StatusRecorder(),
                TrackType.Nats);

            // Act
            adder.AddToWaypointList(new[] { nodes });

            // Assert
            int indexP1 = wptList.FindByWaypoint(p1);

            Assert.AreEqual(1, wptList.EdgesFromCount(indexP1));

            var edge     = wptList.EdgesFrom(indexP1).First();
            var neighbor = wptList.GetEdge(edge).Value;

            Assert.IsTrue(neighbor.Airway == "NATA");

            Assert.IsTrue(neighbor.InnerWaypoints.SequenceEqual(CreateList(p2)));
            Assert.AreEqual(InnerWaypointsType.Track, neighbor.Type);

            var distance = p1.Distance(p2) + p2.Distance(p3);

            Assert.AreEqual(distance, neighbor.Distance);
        }
예제 #11
0
        public void AddLastWaypointTest1()
        {
            var x = new Waypoint("X", 0.0, 0.0);
            var y = new Waypoint("Y", 0.0, 1.0);

            var route = new Route();

            route.AddLastWaypoint(x);

            route.AddLastWaypoint(y, "0", 100.0);

            Assert.IsTrue(y.Equals(route.LastWaypoint));
            Assert.IsTrue("0" == route.Last.Previous.Value.AirwayToNext.Airway);
            Assert.AreEqual(
                100.0, route.Last.Previous.Value.AirwayToNext.Distance, 1E-8);
            Assert.IsTrue(x.Equals(route.Last.Previous.Value.Waypoint));
        }
예제 #12
0
        public void AddLastWaypointTest3EmptyRoute()
        {
            var x     = new Waypoint("X", 0.0, 0.0);
            var route = new Route();

            route.AddLastWaypoint(x);

            Assert.IsTrue(x.Equals(route.LastWaypoint));
        }
예제 #13
0
        public void ConnectRouteMismatchShouldThrowException()
        {
            var x = new Waypoint("X", 0.0, 0.0);

            var route = new Route();

            route.AddLastWaypoint(x);

            Assert.Throws <ArgumentException>(() => route.Connect(GetRoute1()));
        }
예제 #14
0
        public void ConnectRouteTest()
        {
            var x = new Waypoint("X", 0.0, 0.0);
            var y = new Waypoint("Y", 0.0, 1.0);
            var z = new Waypoint("Z", 0.0, 3.0);

            var route = new Route();

            route.AddLastWaypoint(x);
            route.AddLastWaypoint(y, "0");

            var expected = new Route(route);

            route.Connect(GetRoute1());

            expected.AddLastWaypoint(z, "1");

            Assert.IsTrue(expected.Equals(route));
        }
예제 #15
0
        public void AddFirstWaypointTest1()
        {
            var x = new Waypoint("X", 0.0, 0.0);
            var y = new Waypoint("Y", 0.0, 1.0);

            var route = new Route();

            route.AddLastWaypoint(y);

            route.AddFirstWaypoint(x, "0", 100.0);

            Assert.IsTrue(x.Equals(route.FirstWaypoint));
            Assert.IsTrue("0" == route.First.Value.Neighbor.Airway);
            Assert.AreEqual(100.0, route.First.Value.Neighbor.Distance, 1E-8);
            Assert.IsTrue(y.Equals(route.First.Next.Value.Waypoint));
        }