// The returned list is ready to be put out over API and View public List<Restaurant> queryForRestaurantsAndCalculate(IncomingRequestUI request) { if (request == null) return null; restaurantsWithinRadius = new List<Restaurant>(); // Find the lat/long (Point) of the IncomingRequestUI using FilmLocationsDAL Point requestPoint = null; List<Location> locationsForRequestedFilm = fdal.findLocationsByFilm(request.filmName); foreach (Location loc in locationsForRequestedFilm) { if (loc.locnText.Equals(request.location)) { requestPoint = loc.point; } } if (requestPoint == null) return null; // Find all restaurants List<Restaurant> allRestaurants = rdal.findAllRestaurants(); // Create a Calculator obj LocationCalculator calc = new LocationCalculator(); // Iterate through all restaurants in the DB for (int i = 0; i < allRestaurants.Count; i++) { // Passing the centre point, restaurant point and radius into the calculator calc.setNewQuery(requestPoint, allRestaurants[i].point, request.radius); // If the calculator decides the restarant is within the radius... if (calc.isInsideRadius()) { // ...add it to the outgoing list restaurantsWithinRadius.Add(allRestaurants[i]); } } // Return the list of all Restaurants within radius return restaurantsWithinRadius; }
public void isInsideRadiusTest() { LocationCalculator target = new LocationCalculator(); // TODO: Initialize to an appropriate value // Actual distance between locations = 0.94km; // 49-51 W 46th St target.xCentre = 40.756912; target.yCentre = -73.980989; // 4-42 W 58th St target.xLocation = 40.764259; target.yLocation = -73.975325; target.radius = 1; //km bool actual = target.isInsideRadius(); bool expected = true; actual = target.isInsideRadius(); Assert.AreEqual(expected, actual); }
public void isInsideRadiusTestFALSE() { LocationCalculator target = new LocationCalculator(); // TODO: Initialize to an appropriate value // Actual distance between locations = 1.3km; // 49-51 W 46th St target.xCentre = 40.756912; target.yCentre = -73.980989; // 37-39 W 77th St target.xLocation = 40.774361; target.yLocation = -73.975244; target.radius = 1; //km bool actual = target.isInsideRadius(); bool expected = false; actual = target.isInsideRadius(); Assert.AreEqual(expected, actual); }
public void LocationCalculatorConstructorTest() { LocationCalculator target = new LocationCalculator(); LocationCalculator target2 = new LocationCalculator(); Assert.AreEqual(target.radius, target2.radius); Assert.AreEqual(target.xCentre, target2.xCentre); Assert.AreEqual(target.yCentre, target2.yCentre); Assert.AreEqual(target.xLocation, target2.xLocation); Assert.AreEqual(target.yLocation, target2.yLocation); }