Beispiel #1
0
        public void DetermineCustomersToInvite_ThreeCustomersWithinDistance_InvitesThreeCustomers()
        {
            var venue      = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));
            var calculator = new Calculator();
            var customers  = new List <CustomerContract>
            {
                new CustomerContract {
                    Name = "1", UserId = 1, Latitude = 53.3334849, Longitude = -6.2612991
                },
                new CustomerContract {
                    Name = "3", UserId = 3, Latitude = 53.3334593, Longitude = -6.2646894
                },
                new CustomerContract {
                    Name = "2", UserId = 2, Latitude = 53.3334593, Longitude = -6.2646894
                },
                new CustomerContract {
                    Name = "5", UserId = 5, Latitude = 53.2487055, Longitude = -6.5992854
                },
                new CustomerContract {
                    Name = "4", UserId = 4, Latitude = 53.5061796, Longitude = -6.4699798
                },
                new CustomerContract {
                    Name = "6", UserId = 6, Latitude = 53.1970187, Longitude = -6.1308245
                },
            };

            var invitationManager = new InvitationManager(calculator, venue);
            var customersToInvite = invitationManager.DetermineCustomersToInvite(customers, 10);

            Assert.AreEqual(3, customersToInvite.Count());
            Assert.IsTrue(customersToInvite.ElementAt(0).UserId < customersToInvite.ElementAt(1).UserId);
            Assert.IsTrue(customersToInvite.ElementAt(1).UserId < customersToInvite.ElementAt(2).UserId);
        }
Beispiel #2
0
        public void DetermineCustomersToInvite_NullCustomers_ThrowsArgumentNullException()
        {
            var venueLocation     = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));
            var calculator        = new Calculator();
            var invitationManager = new InvitationManager(calculator, venueLocation);

            var customersToInvite = invitationManager.DetermineCustomersToInvite(null, 100);
        }
Beispiel #3
0
        public void DetermineCustomersToInvite_NegativeDistanceToVenue_ThrowsArgumentException()
        {
            var venueLocation     = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));
            var calculator        = new Calculator();
            var customers         = new List <CustomerContract>();
            var invitationManager = new InvitationManager(calculator, venueLocation);

            var customersToInvite = invitationManager.DetermineCustomersToInvite(customers, -100);
        }
Beispiel #4
0
        public void DetermineCustomersToInvite_NoCustomersWithinDistance_InvitesNobody()
        {
            var venue      = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));
            var calculator = new Calculator();
            var customers  = new List <CustomerContract>
            {
                new CustomerContract {
                    Name = "1", UserId = 1, Latitude = 53.2487055, Longitude = -6.5992854
                },
                new CustomerContract {
                    Name = "3", UserId = 3, Latitude = 53.5061796, Longitude = -6.4699798
                },
                new CustomerContract {
                    Name = "2", UserId = 2, Latitude = 53.1970187, Longitude = -6.1308245
                },
            };

            var invitationManager = new InvitationManager(calculator, venue);
            var customersToInvite = invitationManager.DetermineCustomersToInvite(customers, 10);

            Assert.AreEqual(0, customersToInvite.Count());
        }
Beispiel #5
0
        public void DetermineCustomersToInvite_AllCustomersWithinDistance_InvitesAllCustomers()
        {
            var venue      = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));
            var calculator = new Calculator();
            var customers  = new List <CustomerContract>
            {
                new CustomerContract {
                    Name = "1", UserId = 1, Latitude = 53.3334849, Longitude = -6.2612991
                },
                new CustomerContract {
                    Name = "3", UserId = 3, Latitude = 53.3334593, Longitude = -6.2646894
                },
                new CustomerContract {
                    Name = "2", UserId = 2, Latitude = 53.3334593, Longitude = -6.2646894
                },
            };

            var invitationManager = new InvitationManager(calculator, venue);
            var customersToInvite = invitationManager.DetermineCustomersToInvite(customers, 10);

            Assert.AreEqual(customers.Count, customersToInvite.Count());
            Assert.IsTrue(customersToInvite.ElementAt(0).UserId < customersToInvite.ElementAt(1).UserId);
            Assert.IsTrue(customersToInvite.ElementAt(1).UserId < customersToInvite.ElementAt(2).UserId);
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("Please specify the path to the input file in the command line arguments.");
                return;
            }

            if (string.IsNullOrWhiteSpace(args[0]) || !File.Exists(args[0]))
            {
                Console.WriteLine("Input file not found.");
                return;
            }

            try
            {
                var lines      = File.ReadAllLines(args[0]);
                var customers  = new List <CustomerContract>();
                var calculator = new Calculator();

                var dublinOfficeLocation = new RadianCoordinate(Calculator.ConvertDegreesToRadians(53.339428), Calculator.ConvertDegreesToRadians(-6.257664));

                foreach (var line in lines)
                {
                    try
                    {
                        var customer = CustomerContract.Deserialize(line);

                        if (customer.IsValid())
                        {
                            customers.Add(customer);
                        }
                    }
                    catch (JsonSerializationException e)
                    {
                        continue;
                    }
                    catch (ArgumentNullException e)
                    {
                        continue;
                    }
                    catch (ArgumentException e)
                    {
                        continue;
                    }
                }

                var invitationManager = new InvitationManager(calculator, dublinOfficeLocation);
                var customersToInvite = invitationManager.DetermineCustomersToInvite(customers, 100d);

                Console.WriteLine("The following customers should be invited:");

                foreach (var customer in customersToInvite)
                {
                    Console.WriteLine($"{customer.Name} ({customer.UserId})");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"An unexpected error occurred: {e.Message}");
            }

            Console.WriteLine("Press any key to exit...");
            Console.ReadKey();
        }