Exemplo n.º 1
0
        public void RestaurantSignature_Equals()
        {
            // Create two different signatures using the same parameters
            RestaurantSignature S1 = new RestaurantSignature("A", 3);
            RestaurantSignature S2 = new RestaurantSignature("A", 3);

            // Based on how equals method is defined, true should be returned:
            Assert.IsTrue(S1.Equals(S2));

            // Create another signature with the same rating, but different name
            RestaurantSignature S3 = new RestaurantSignature("B", 3);

            // Based on how equals method is defined, false should be returned:
            // Since A is not the same as B
            Assert.IsFalse(S2.Equals(S3));

            // Create another signature with the same name, but different rating
            RestaurantSignature S4 = new RestaurantSignature("A", 4);

            // Based on how equals method is defined, false should be returned:
            // Since 3!= 4
            Assert.IsFalse(S2.Equals(S4));

            // Create another signature with different name and rating
            RestaurantSignature S5 = new RestaurantSignature("C", 1);

            // Based on how equals method is defined, false should be returned:
            // Since 3!= 4
            Assert.IsFalse(S2.Equals(S5));
        }
Exemplo n.º 2
0
        public void RestaurantSignature_RatingAndNameAreValid()
        {
            RestaurantSignature restaurantSignature = new RestaurantSignature("A", 1);

            Assert.IsTrue(restaurantSignature.Name.Equals("A"));
            Assert.IsTrue(restaurantSignature.Rating == 1);
        }
Exemplo n.º 3
0
        public void Case_ReversedRestaurants()
        {
            //Team needs: total 50 meals including 5 vegetarians and 7 gluten free.
            // Please note, that restaurant B is created first, restaurant A is created next
            OrderWishList order = new OrderWishList(5, 7, 0, 0, 50);

            RestaurantsFactory factory = new RestaurantsFactory();

            factory.CreateRestaurant("B", 3, 20, 20, 0, 0, 100);
            factory.CreateRestaurant("A", 5, 4, 0, 0, 0, 40);

            OrderProcessor processor = new OrderProcessor(order, factory);

            List <MealsReadyForDelivery> totalOrders = processor.TotalOrders;


            // Expected first element at index 0
            // Restaurant A has a rating of 5/5 and can serve 4 vegetarians, 36 other.
            RestaurantSignature expectS0 = new RestaurantSignature("A", 5);
            Dictionary <RestaurantMeal.MealType, int> expectD0 = new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.Vegetarian, 4 },
                { RestaurantMeal.MealType.Other, 36 },
            };
            MealsReadyForDelivery readyForDelivery0 = new MealsReadyForDelivery(expectS0, expectD0);



            // Expected second element at index 1
            // Restaurant B has a rating of 3 / 5 and can serve 20 vegetarians, and 20 gluten free, 60 other.
            RestaurantSignature expectS1 = new RestaurantSignature("B", 3);
            Dictionary <RestaurantMeal.MealType, int> expectD1 = new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.Vegetarian, 1 },
                { RestaurantMeal.MealType.GlutenFree, 7 },
                { RestaurantMeal.MealType.Other, 2 },
            };
            MealsReadyForDelivery readyForDelivery1 = new MealsReadyForDelivery(expectS1, expectD1);



            // Check to see that expected meal orders results are the same, as actual
            Assert.AreEqual(totalOrders.Count, 2);
            Assert.IsTrue(Verifier.MealsReayForDeliveryAreEq(totalOrders[0], readyForDelivery0));
            Assert.IsTrue(Verifier.MealsReayForDeliveryAreEq(totalOrders[1], readyForDelivery1));
        }
        public void Case_OrderMoreThanAvailable()
        {
            //Team needs: total 50 meals including 5 vegetarians and 7 gluten free.
            OrderWishList order = new OrderWishList(5, 7, 0, 0, 50);


            // Create Restaurants
            RestaurantsFactory factory = new RestaurantsFactory();

            factory.CreateRestaurant("B", 1, 1, 1, 0, 0, 2);
            factory.CreateRestaurant("A", 2, 1, 1, 0, 0, 2);

            OrderProcessor processor = new OrderProcessor(order, factory);
            List <MealsReadyForDelivery> totalOrders = processor.TotalOrders;



            // Expected first element at index 0
            // Restaurant A has a rating of 2/5 and can serve 1 vegetarian and 1 gluten free, total: 2
            RestaurantSignature expectS0 = new RestaurantSignature("A", 2);
            Dictionary <RestaurantMeal.MealType, int> expectD0 = new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.Vegetarian, 1 },
                { RestaurantMeal.MealType.GlutenFree, 1 },
            };
            MealsReadyForDelivery readyForDelivery0 = new MealsReadyForDelivery(expectS0, expectD0);



            // Expected second element at index 1
            // Restaurant B has a rating of 1 / 5 and can serve 1 vegetarian and 1 gluten free, total: 2
            RestaurantSignature expectS1 = new RestaurantSignature("B", 1);
            Dictionary <RestaurantMeal.MealType, int> expectD1 = new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.Vegetarian, 1 },
                { RestaurantMeal.MealType.GlutenFree, 1 },
            };
            MealsReadyForDelivery readyForDelivery1 = new MealsReadyForDelivery(expectS1, expectD1);



            // Check to see that expected meal orders results are the same, as actual
            Assert.AreEqual(totalOrders.Count, 2);
            Assert.IsTrue(Verifier.MealsReayForDeliveryAreEq(totalOrders[0], readyForDelivery0));
            Assert.IsTrue(Verifier.MealsReayForDeliveryAreEq(totalOrders[1], readyForDelivery1));
        }
        public void ObjectProcessor_ProcessOrder()
        {
            // Create order processor:
            OrderProcessor orderProcessor = new OrderProcessor();

            // Create a wish list, where 3 nut free meal should be still ordered
            OrderWishList orderWishList = new OrderWishList();

            orderWishList.MealsToOrder = new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.Vegetarian, 0 },
                { RestaurantMeal.MealType.GlutenFree, 0 },
                { RestaurantMeal.MealType.NutFree, 3 },
                { RestaurantMeal.MealType.FishFree, 0 },
                { RestaurantMeal.MealType.Other, 0 },
            };


            // Add a wish list to order processor
            orderProcessor.OrderWishList = orderWishList;

            // Add a restaurant to order processor, which has 4 nut free meals
            orderProcessor.ListOfRestaurants.Add(new Restaurant("A", 5, 0, 0, 4, 0, 4));

            // Process order
            orderProcessor.ProcessOrder();

            // Check that order processor has processed the order properly
            // It is supposed that 3 nut free meals were ordered from the restaurant A
            MealsReadyForDelivery mealsReadyForDelivery = orderProcessor.TotalOrders[0];

            // Expected:
            RestaurantSignature expectSignature = new RestaurantSignature("A", 5);
            Dictionary <RestaurantMeal.MealType, int> expectReadyMeals =
                new Dictionary <RestaurantMeal.MealType, int>
            {
                { RestaurantMeal.MealType.NutFree, 3 }
            };

            // Check that actual is the same as expected:
            Assert.IsTrue(mealsReadyForDelivery.Signature.Equals(expectSignature));
            Assert.IsTrue(Verifier.DictionariesAreEq(mealsReadyForDelivery.ReadyMeals, expectReadyMeals));
        }