public void it_should_calculate_the_correct_distance(double latitude, double longitude, double expectedDistance)
            {
                var destination = new TerraLocation(latitude, longitude);

                double actualDistance = _source.CalculateDistanceInKmTo(destination);

                Assert.AreEqual(expectedDistance, actualDistance);
            }
        private IEnumerable<CustomerRecord> SelectCustomersWithinRange(TerraLocation officeLocation, double distanceFromOfficeInKm)
        {
            Dictionary<int, CustomerRecord> invitees = new Dictionary<int, CustomerRecord>();
            List<CustomerRecord> customerRecords = _customerRecordsProvider.GetCustomerRecords();

            foreach (var customerRecord in customerRecords)
            {
                if (CustomerIsWithinRange(officeLocation, distanceFromOfficeInKm, customerRecord))
                {
                    invitees.Add(customerRecord.UserId, customerRecord);
                }
            }

            return invitees.Values.OrderBy(c=> c.UserId);
        }
Exemplo n.º 3
0
        public double CalculateDistanceInKmTo(TerraLocation location)
        {
            double latitude1Rad = Latitude.ConvertToRadians();
            double longitude1Rad = Longitude.ConvertToRadians();
            double latititude2Rad = location.Latitude.ConvertToRadians();
            double longitude2Rad = location.Longitude.ConvertToRadians();

            double logitudeDiff = Math.Abs(longitude1Rad - longitude2Rad);

            double centralAngle =
                Math.Acos(
                    Math.Sin(latititude2Rad) * Math.Sin(latitude1Rad) +
                    Math.Cos(latititude2Rad) * Math.Cos(latitude1Rad) * Math.Cos(logitudeDiff));

            return Math.Round(TerraRadiusInKm * centralAngle, 3, MidpointRounding.AwayFromZero);
        }
        public void Generate(TerraLocation officeLocation, double distanceFromOfficeInKm)
        {
            if (officeLocation == null)
            {
                throw new ArgumentNullException("officeLocation");
            }

            if (distanceFromOfficeInKm <= 0)
            {
                throw new ArgumentOutOfRangeException("distanceFromOffice", "Value should be greater than zero");
            }

            IEnumerable<CustomerRecord> invitees = SelectCustomersWithinRange(officeLocation, distanceFromOfficeInKm);

            WriteInvitations(invitees);
        }
        private bool CustomerIsWithinRange(TerraLocation officeLocation, double distanceFromOfficeInKm, CustomerRecord customerRecord)
        {
            double distanceToCustomer = officeLocation.CalculateDistanceInKmTo(customerRecord.Location);

            return distanceToCustomer <= distanceFromOfficeInKm;
        }
 public void SetUp()
 {
     _source = new TerraLocation(53.3472, -6.259);
 }