Esempio n. 1
0
        public void CalculateDistanceOnSamePointTest()
        {
            var point1 = new DistancePoint {
                Latitude = 1, Longitude = 1
            };
            var result = instanceUnderTest.CalculateDistance(point1, point1, MeasureUnit.Km, DistanceCalculationMethod.GeodesicCurve);

            Assert.AreEqual(0, result);
        }
Esempio n. 2
0
        public ActionResult <DistanceResponse> Get(DistanceCalculationMethod distanceMethod, MeasureUnit measureUnit,
                                                   [FromQuery][Range(-90, 90, ErrorMessage = "Must be in [-90, 90] interval")] double point1Latitude,
                                                   [FromQuery][Range(-180, 180, ErrorMessage = "Must be in [-180, 180] interval")] double point1Longitude,
                                                   [FromQuery][Range(-90, 90, ErrorMessage = "Must be in [-90, 90] interval")] double point2Latitude,
                                                   [FromQuery][Range(-180, 180, ErrorMessage = "Must be in [-180, 180] interval")] double point2Longitude)
        {
            var point1 = new DistancePoint
            {
                Latitude  = point1Latitude,
                Longitude = point1Longitude
            };
            var point2 = new DistancePoint
            {
                Latitude  = point2Latitude,
                Longitude = point2Longitude
            };

            return(new ActionResult <DistanceResponse>(new DistanceResponse
            {
                Distance = _distanceStrategy.CalculateDistance(point1, point2, measureUnit, distanceMethod)
            }));
        }
Esempio n. 3
0
        public void CalculateDistanceWithMatchingCalculatorTest()
        {
            //setup
            var point1 = new DistancePoint {
                Latitude = 1, Longitude = 1
            };
            var point2 = new DistancePoint {
                Latitude = 1, Longitude = 2
            };
            var inputList      = new List <IDistanceCalculator>();
            var mockCalculator = new Mock <IDistanceCalculator>();

            mockCalculator.Setup(x => x.DistanceCalculationMethod).Returns(DistanceCalculationMethod.GeodesicCurve);
            mockCalculator.Setup(x => x.CalculateDistance(point1, point2, MeasureUnit.Km)).Returns(1);
            inputList.Add(mockCalculator.Object);
            instanceUnderTest = new DistanceCalculationStrategy(inputList);

            //execution
            var result = instanceUnderTest.CalculateDistance(point1, point2, MeasureUnit.Km, DistanceCalculationMethod.GeodesicCurve);

            Assert.AreEqual(1, result);
        }