示例#1
0
def test_checkout_mixed_products():
    assert 50 == checkout("A")
    assert 50 + 30 == checkout("AB")  # clearer this way
    assert 50 * 2 + 30 == checkout("ABA")
    assert 130 + 45 + 20 == checkout("ABBACA")
    assert 45 + 15 == checkout("BBD")

    assert 80 == checkout("EEB")
    assert 80 == checkout("EE")

    assert 10 == checkout("F")
    assert 20 == checkout("FF")
    assert 20 == checkout("FFF")
def test_checkout_invalid_string_returns_fail(mock_sku_service,
                                              mock_validation_service):
    mock_validation_service.return_value.validate_basket.return_value = False

    output = checkout("things")

    assert output == -1
示例#3
0
 def test_standard_prices(self):
     """Test all of the standard item prices"""
     STANDARD_PRICES = {
         "A": 50,
         "B": 30,
         "C": 20,
         "D": 15,
         "E": 40,
         "F": 10,
         "G": 20,
         "H": 10,
         "I": 35,
         "J": 60,
         "K": 70,
         "L": 90,
         "M": 15,
         "N": 40,
         "O": 10,
         "P": 50,
         "Q": 30,
         "R": 50,
         "S": 20,
         "T": 20,
         "U": 40,
         "V": 50,
         "W": 20,
         "X": 17,
         "Y": 20,
         "Z": 21
     }
     for item, price in STANDARD_PRICES.items():
         setattr(self, "test_item_{}".format(item),
                 self.assertEquals(checkout(item), price))
    def test_checkout_ok(self) -> None:
        in_out = {
            "": 0,
            "A": 50,
            "AB": 80,
            "C": 20,
            "AAA": 130,
            "AAAA": 180,
            "AAAAA": 200,
            "AAAAAA": 250,
            "CCCCC": 100,
            "EE": 80,
            "DABDBC": 145,
            "BE": 70,
            "BEE": 80,
            "BBEE": 110,
            "BBBEE": 125,
            "BBBEEE": 165,
            "BBBEEEE": 190,
            "F": 10,
            "FF": 20,
            "FFF": 20,
            "STS": 45,
            "STST": 65,
            "XYZ": 45,
            "XXY": 45,
            "ZZXX": 62,
        }

        for input_, output in in_out.items():
            assert checkout(input_) == output, input_
    def test_checkout_invalid_input_only_numbers(self):
        """ Tests if checkout function is returning -1 for input that only has numbers.
        """
        mock_input = '123'
        expected_value = -1
        returned_value = checkout(mock_input)

        assert expected_value == returned_value
def test_checkout_unable_to_load_sku_returns_fail(mock_sku_service,
                                                  mock_validation_service):
    mock_sku_service.return_value.load_from_json_file.side_effect = OverflowError(
    )

    output = checkout("stuff")

    assert output == -1
    def test_checkout_invalid_input_lowercases(self):
        """ Tests if checkout function is returning -1 when input has lowercase letters.
        """
        mock_input = 'AAAACCCDDDc'
        expected_value = -1
        returned_value = checkout(mock_input)

        assert expected_value == returned_value
    def test_checkout_valid_input(self):
        """ Tests if checkout function is returning the correct value for a valid input
        For '3A B C' it should return 130+30+20=180
        """
        mock_input = 'AAABC'
        expected_value = 180
        returned_value = checkout(mock_input)

        assert expected_value == returned_value
def test_checkout_valid_skus_returns_price(mock_sku_service,
                                           mock_validation_service,
                                           mock_pricing_service):
    mock_validation_service.return_value.validate_basket.return_value = True
    mock_pricing_service.return_value.get_price.return_value = 75

    output = checkout("this")

    assert output == 75
示例#10
0
 def test_a_bundle(self):
     assert checkout_solution.checkout("AAAAA") == 200
     assert checkout_solution.checkout("AAAAAA") == 250
     assert checkout_solution.checkout("AAAAAAA") == 300
     assert checkout_solution.checkout("AAAAAAAA") == 330
     assert checkout_solution.checkout("AAAAAAAAA") == 380
     assert checkout_solution.checkout("AAAAAEEBAAABB") == 455
     assert checkout_solution.checkout("ABCDECBAABCABBAAAEEAA") == 665
示例#11
0
def test_a_price():
    assert 50 == checkout("A")
    assert 100 == checkout("AA")
    assert 130 == checkout("AAA")
    assert 180 == checkout("AAAA")
    assert 200 == checkout("AAAAA")
    assert 200 + 50 * 2 == checkout("AAAAAAA")
示例#12
0
def test_f_price():
    assert 10 == checkout("F")
    assert 20 == checkout("FF")
    assert 20 == checkout("FFF")
    assert 30 == checkout("FFFF")
    assert 40 == checkout("FFFFF")
    assert 40 == checkout("FFFFFF")
示例#13
0
 def test_checkout_returns_correct_price(self):
     test_cases = {
         '': 0,
         'a': -1,
         'ABCa': -1,
         'A': 50,
         'AA': 100,
         'AAA': 130,
         'AAAAA': 200,
         'B': 30,
         'BB': 45,
         'BBEE': 110,
         'ABAA': 160,
         'AAAAABBEE': 310,
         'AAAAAAAA': 330,
         'EEB': 80,
         'ABCDECBAABCABBAAAEEAA': 665,
         'FFF': 20,
         'FF': 20,
         'HHHHH': 45,
         'HHHHHHHHHH': 80,
         'HHHHHHHHHHHHH': 110,
         'KK': 150,
         'NNN': 120,
         'NNNM': 120,
         'NNNMM': 135,
         'PPPPP': 200,
         'PPPPPPPPPP': 400,
         'QQQ': 80,
         'RRR': 150,
         'RRRQ': 150,
         'QQQRRRQ': 230,
         'UUU': 120,
         'UUAU': 170,
         'VV': 90,
         'VVV': 130,
         'VVVVV': 220,
         'UUUU': 120
     }
     for k, v in test_cases.items():
         assert checkout_solution.checkout(k) == v
示例#14
0
 def test_bogo_four_u_discount(self):
     self.assertEqual(checkout("UUUU"), 120)
示例#15
0
 def test_basic_discount_ten_h(self):
     self.assertEqual(checkout("HHHHHHHHHH"), 80)
示例#16
0
 def test_group_three_r_discount_q(self):
     self.assertEqual(checkout("RRRQ"), 150)
示例#17
0
 def test_bogo_three_u(self):
     self.assertEqual(checkout("UUU"), 120)
示例#18
0
 def test_bogo_three_q(self):
     self.assertEqual(checkout("QQQ"), 80)
示例#19
0
 def test_group_three_r(self):
     self.assertEqual(checkout("RRR"), 150)
示例#20
0
 def test_basic_discount_five_p(self):
     self.assertEqual(checkout("PPPPP"), 200)
示例#21
0
 def test_bad_input(self):
     self.assertEqual(checkout(-1), -1)
示例#22
0
 def test_group_three_n(self):
     self.assertEqual(checkout("NNN"), 120)
示例#23
0
 def test_group_three_n_discount_m(self):
     self.assertEqual(checkout("NNNM"), 120)
示例#24
0
 def test_bogo_e_and_b2(self):
     self.assertEqual(checkout("BBEE"), 110)
示例#25
0
 def test_basic_discount_six_a(self):
     self.assertEqual(checkout("AAAAAA"), 250)
示例#26
0
 def test_bogo_one_f(self):
     self.assertEqual(checkout("F"), 10)
示例#27
0
 def test_single_item(self):
     self.assertEqual(checkout("A"), 50)
示例#28
0
 def test_bogo_three_f(self):
     self.assertEqual(checkout("FFF"), 20)
示例#29
0
 def test_basic_discount_five_h(self):
     self.assertEqual(checkout("HHHHH"), 45)
示例#30
0
 def test_basic_discount_2_k(self):
     self.assertEqual(checkout("KK"), 120)