Пример #1
0
        /// <summary>
        /// Tries to parse a start direction from given location description. Some locations, e.g.
        /// from the DHV Geländedatenbank, have the start directions in the description, after a
        /// certain text.
        /// </summary>
        /// <param name="description">location description</param>
        /// <param name="takeoffDirections">parsed takeoff directions</param>
        /// <returns>true when a takeoff direction could be parsed, or false when not</returns>
        private static bool TryParseStartDirectionFromDescription(string description, out TakeoffDirections takeoffDirections)
        {
            takeoffDirections = TakeoffDirections.None;

            const string StartDirectionText = "Startrichtung ";
            int          posStartDirection  = description.IndexOf(StartDirectionText);

            if (posStartDirection == -1)
            {
                return(false);
            }

            int posLineBreak = description.IndexOf("<br", posStartDirection);

            if (posLineBreak == -1)
            {
                posLineBreak = description.Length;
            }

            posStartDirection += StartDirectionText.Length;

            string direction = description.Substring(posStartDirection, posLineBreak - posStartDirection);

            return(TakeoffDirectionsHelper.TryParse(direction, out takeoffDirections));
        }
Пример #2
0
        public void TestTryParseCorrectTakeoffTexts()
        {
            // set up
            string[] correctTakeoffTexts = new string[]
            {
                "N",
                "SSW",
                "N-E",
                "N-SSE",
                "N-S",
                "N-SSW",
                "E-WSW",
                "E-W",
                "E-WNW",
                "N-NNW",
                "S-SW,NW-W",
                "S-SW, NW-W",
                "O-NO",
                "West takeoff (W-SW)",
                "Takeoff (N, O, S)",
                "Takeoff (NO, NW)",
            };

            foreach (var text in correctTakeoffTexts)
            {
                // run
                bool result = TakeoffDirectionsHelper.TryParse(text, out TakeoffDirections takeoffDirections);

                Debug.WriteLine($"text={text} directions={takeoffDirections}");

                // check
                Assert.IsTrue(result, "text must have been parsed correctly");
                Assert.IsTrue(takeoffDirections != TakeoffDirections.None, "takeoff direction must not be empty");
            }
        }
Пример #3
0
 /// <summary>
 /// Adds takeoff directions value to every location in the list
 /// </summary>
 /// <param name="locationList">location list to modify</param>
 private static void AddTakeoffDirections(List <Location> locationList)
 {
     foreach (var location in locationList)
     {
         if (TakeoffDirectionsHelper.TryParse(location.Name, out TakeoffDirections takeoffDirections))
         {
             location.TakeoffDirections = takeoffDirections;
         }
         else if (TryParseStartDirectionFromDescription(location.Description, out TakeoffDirections takeoffDirections2))
         {
             location.TakeoffDirections = takeoffDirections2;
         }
     }
 }
Пример #4
0
        public void TestModifyAdjacentDirectionsFromView()
        {
            // check
            Assert.AreEqual(
                TakeoffDirections.NE | TakeoffDirections.NNE | TakeoffDirections.ENE,
                TakeoffDirectionsHelper.ModifyAdjacentDirectionsFromView(TakeoffDirections.NE),
                "modified takeoff directions value must contain adjacent directions");

            Assert.AreEqual(
                TakeoffDirections.All,
                TakeoffDirectionsHelper.ModifyAdjacentDirectionsFromView(
                    TakeoffDirections.N | TakeoffDirections.NE |
                    TakeoffDirections.E | TakeoffDirections.SE |
                    TakeoffDirections.S | TakeoffDirections.SW |
                    TakeoffDirections.W | TakeoffDirections.NW),
                "modified takeoff directions value must contain all directions");
        }
Пример #5
0
        public void TestTryParseInvalidTakeoffTexts()
        {
            // set up
            string[] invalidTakeoffTexts = new string[]
            {
                "SR",
                "SSW-",
                "N-NNW-",
                "S-SW NW-W",
            };

            foreach (var text in invalidTakeoffTexts)
            {
                // run
                bool result = TakeoffDirectionsHelper.TryParse(text, out TakeoffDirections takeoffDirections);

                // check
                Assert.IsFalse(result, "text parsing must have failed");

                Assert.IsTrue(takeoffDirections == TakeoffDirections.None, "takeoff direction must be None");
            }
        }