def test_calculate_valid_input_multiple_items(self): """ Tests the checkout handler calculate function a multiple items in the input. For the mock input provided it should return 130+45+20=195. """ special_offers_item_a = [SpecialOffer(3, 130, None), SpecialOffer(5, 200, None)] special_offers_item_b = [SpecialOffer(2, 45, None)] item_a = StockKeepUnit('A', 50, special_offers_item_a) item_b = StockKeepUnit('B', 30, special_offers_item_b) item_c = StockKeepUnit('C', 20, []) item_d = StockKeepUnit('D', 15, []) special_offers_item_e = [SpecialOffer(2, 0, item_b)] item_e = StockKeepUnit('E', 40, special_offers_item_e) mock_supermarket = SuperMarket([item_a, item_b, item_c, item_d, item_e]) mock_input = 'AAABBC' expected_return_value = 195 returned_value = CheckoutHandler.calculate(mock_input, mock_supermarket) assert expected_return_value == returned_value
def test_calculate_empty_input(self): """ Tests the checkout handler calculate function with an empty input Since it's empty it should return 0. """ special_offers_item_a = [SpecialOffer(3, 130, None), SpecialOffer(5, 200, None)] special_offers_item_b = [SpecialOffer(2, 45, None)] item_a = StockKeepUnit('A', 50, special_offers_item_a) item_b = StockKeepUnit('B', 30, special_offers_item_b) item_c = StockKeepUnit('C', 20, []) item_d = StockKeepUnit('D', 15, []) special_offers_item_e = [SpecialOffer(2, 0, item_b)] item_e = StockKeepUnit('E', 40, special_offers_item_e) mock_supermarket = SuperMarket([item_a, item_b, item_c, item_d, item_e]) mock_input = '' expected_return_value = 0 returned_value = CheckoutHandler.calculate(mock_input, mock_supermarket) assert expected_return_value == returned_value
def test_calculate_total_checkout_value_service_with_same_items_count(self): """ Tests calculating the checkout value with single quantity items. For the provided mock values should return: 50+30+20+15+40 = 155 """ special_offers_item_a = [SpecialOffer(3, 130, None), SpecialOffer(5, 200, None)] special_offers_item_b = [SpecialOffer(2, 45, None)] item_a = StockKeepUnit('A', 50, special_offers_item_a) item_b = StockKeepUnit('B', 30, special_offers_item_b) item_c = StockKeepUnit('C', 20, []) item_d = StockKeepUnit('D', 15, []) special_offers_item_e = [SpecialOffer(2, 0, item_b)] item_e = StockKeepUnit('E', 40, special_offers_item_e) mock_supermarket = SuperMarket([item_a, item_b, item_c, item_d, item_e]) input_items_count = {'A': 1, 'B': 1, 'C': 1, 'D': 1, 'E': 1} expected_value = 155 service = CalculateTotalCheckoutValueService(input_items_count, mock_supermarket) returned_value = service.call() assert returned_value, expected_value