コード例 #1
0
        public void TestInvalidThirdDimension()
        {
            var pairs = new List <LatLngZ>();

            pairs.Add(new LatLngZ(50.1022829, 8.6982122));
            ThirdDimension invalid = (ThirdDimension)999;

            Assert.Throws <ArgumentException>(() =>
            {
                PolylineEncoderDecoder.Encode(pairs, 5, invalid, 0);
            });
        }
コード例 #2
0
        public void TestLatLngZEncode()
        {
            var tuples = new List <LatLngZ>();

            tuples.Add(new LatLngZ(50.1022829, 8.6982122, 10));
            tuples.Add(new LatLngZ(50.1020076, 8.6956695, 20));
            tuples.Add(new LatLngZ(50.1006313, 8.6914960, 30));
            tuples.Add(new LatLngZ(50.0987800, 8.6875156, 40));

            var expected = "BlBoz5xJ67i1BU1B7PUzIhaUxL7YU";
            var computed = PolylineEncoderDecoder.Encode(tuples, 5, ThirdDimension.Altitude, 0);

            Assert.AreEqual(computed, expected);
        }
コード例 #3
0
        public void TestSimpleLatLngEncoding()
        {
            var pairs = new List <LatLngZ>();

            pairs.Add(new LatLngZ(50.1022829, 8.6982122));
            pairs.Add(new LatLngZ(50.1020076, 8.6956695));
            pairs.Add(new LatLngZ(50.1006313, 8.6914960));
            pairs.Add(new LatLngZ(50.0987800, 8.6875156));

            var expected = "BFoz5xJ67i1B1B7PzIhaxL7Y";
            var computed = PolylineEncoderDecoder.Encode(pairs, 5, ThirdDimension.Absent, 0);

            Assert.AreEqual(computed, expected);
        }
コード例 #4
0
        public void TestInvalidCoordinates()
        {
            //Null coordinates
            Assert.Throws <ArgumentException>(() =>
            {
                PolylineEncoderDecoder.Encode(null, 5, ThirdDimension.Absent, 0);
            });


            //Empty coordinates list test
            Assert.Throws <ArgumentException>(() =>
            {
                PolylineEncoderDecoder.Encode(new List <LatLngZ>(), 5, ThirdDimension.Absent, 0);
            });
        }
コード例 #5
0
        public void EncodedFlexilineMatchesDecodedResultTest()
        {
            using (var decodedEnumerator = File.ReadLines("../../../../../../test/round_half_up/decoded.txt").GetEnumerator())
            {
                foreach (var flexiline in File.ReadLines("../../../../../../test/round_half_up/encoded.txt"))
                {
                    decodedEnumerator.MoveNext();
                    var testResultStr = decodedEnumerator.Current;

                    var expectedResult = ParseExpectedTestResult(testResultStr);

                    var decoded = PolylineEncoderDecoder.Decode(flexiline);
                    var encoded = PolylineEncoderDecoder.Encode(
                        decoded,
                        expectedResult.Precision.Precision2d,
                        expectedResult.Precision.Type3d,
                        expectedResult.Precision.Precision3d);

                    ThirdDimension thirdDimension = PolylineEncoderDecoder.GetThirdDimension(encoded);
                    Assert.AreEqual(expectedResult.Precision.Type3d, thirdDimension);

                    for (int i = 0; i < decoded.Count; i++)
                    {
                        AssertEqualWithPrecision(
                            expectedResult.Coordinates[i].Lat,
                            decoded[i].Lat,
                            expectedResult.Precision.Precision2d);

                        AssertEqualWithPrecision(
                            expectedResult.Coordinates[i].Lng,
                            decoded[i].Lng,
                            expectedResult.Precision.Precision2d);

                        AssertEqualWithPrecision(
                            expectedResult.Coordinates[i].Z,
                            decoded[i].Z,
                            expectedResult.Precision.Precision3d);
                    }

                    if (flexiline != encoded)
                    {
                        Console.WriteLine($@"WARNING expected {flexiline} but got {encoded}");
                    }
                }
            }
        }
コード例 #6
0
        public void TestComplexLatLngEncoding()
        {
            var pairs = new List <LatLngZ>();

            pairs.Add(new LatLngZ(52.5199356, 13.3866272));
            pairs.Add(new LatLngZ(52.5100899, 13.2816896));
            pairs.Add(new LatLngZ(52.4351807, 13.1935196));
            pairs.Add(new LatLngZ(52.4107285, 13.1964502));
            pairs.Add(new LatLngZ(52.38871, 13.1557798));
            pairs.Add(new LatLngZ(52.3727798, 13.1491003));
            pairs.Add(new LatLngZ(52.3737488, 13.1154604));
            pairs.Add(new LatLngZ(52.3875198, 13.0872202));
            pairs.Add(new LatLngZ(52.4029388, 13.0706196));
            pairs.Add(new LatLngZ(52.4105797, 13.0755529));

            var expected = "BF05xgKuy2xCx9B7vUl0OhnR54EqSzpEl-HxjD3pBiGnyGi2CvwFsgD3nD4vB6e";
            var computed = PolylineEncoderDecoder.Encode(pairs, 5, ThirdDimension.Absent, 0);

            Assert.AreEqual(computed, expected);
        }