/// <summary>
        /// Splits Coordinate test string to get value to parse and expected output.
        /// Checks proper parsing and value
        /// </summary>
        /// <param name="val">Test string value</param>
        private void Parse_Check(string val)
        {
            var    vals        = val.Split('#'); //First part of string is value to parse, seconds is expected string value after parse
            string coordString = vals[0];
            string expected    = vals[1];

            CoordinatePart c = CoordinatePart.Parse(coordString);//Will throw exception and fail if incorrect (intended behavior)

            //CHECK STRING COMPARISON, BUT REPLACE , and . with * to avoid cultural mismatch
            Assert.AreEqual(expected.Replace(",", "*").Replace(".", "*"), c.ToString().Replace(",", "*").Replace(".", "*"), $"{vals} parsed as {c.ToString().Replace(",", "*").Replace(".", "*")} but {expected.Replace(",", "*").Replace(".", "*")} was expected.");
        }
        public void CoordinatePart_Parse_Wrap_Check()
        {
            CoordinatePart cp = CoordinatePart.Parse("45");

            Assert.AreEqual(45, cp.ToDouble());
            Assert.AreEqual(CoordinatesPosition.N, cp.Position);

            cp = CoordinatePart.Parse("45", CoordinateType.Long);
            Assert.AreEqual(45, cp.ToDouble());
            Assert.AreEqual(CoordinatesPosition.E, cp.Position);
        }
Ejemplo n.º 3
0
        //Verifies that Parse is wrapping Try_Parse correctly
        private static void Parse_Wrap_Tests()
        {
            bool pass = true;

            string        coord   = "45.6, 22.4";
            EagerLoad     el      = new EagerLoad(EagerLoadType.Celestial | EagerLoadType.Cartesian | EagerLoadType.ECEF);
            CartesianType cType   = CartesianType.ECEF;
            DateTime      geoDate = new DateTime(2020, 3, 10, 10, 10, 12);

            Coordinate parseCoord;
            Coordinate tryParseCoord;

            parseCoord = Coordinate.Parse(coord);
            Coordinate.TryParse(coord, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, geoDate);
            Coordinate.TryParse(coord, geoDate, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, cType);
            Coordinate.TryParse(coord, cType, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, geoDate, cType);
            Coordinate.TryParse(coord, geoDate, cType, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, el);
            Coordinate.TryParse(coord, el, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, geoDate, el);
            Coordinate.TryParse(coord, geoDate, el, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, cType, el);
            Coordinate.TryParse(coord, cType, el, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            parseCoord = Coordinate.Parse(coord, geoDate, cType, el);
            Coordinate.TryParse(coord, geoDate, cType, el, out tryParseCoord);
            if (!Parse_Wrap_Check(parseCoord, tryParseCoord, false))
            {
                pass = false;
            }

            //CoordinatePart Check

            CoordinatePart cp = CoordinatePart.Parse("45");

            if (cp.ToDouble() != 45 || cp.Position != CoordinatesPosition.N)
            {
                pass = false;
            }

            cp = CoordinatePart.Parse("45", CoordinateType.Long);
            if (cp.ToDouble() != 45 || cp.Position != CoordinatesPosition.E)
            {
                pass = false;
            }

            Pass.Write("Parse Wrapper Test", pass);
        }