def test_offers(): items = 'A' * 6 + 'B' * 10 + 'C' * 20 assert checkout(items, offers=OFFERS, buy_offers=[]) == 225 + 510 + 1400 #Lets shuffle to make sure that works items_shuffled = shuffle_str(items) assert checkout(items_shuffled, offers=OFFERS, buy_offers=[]) == 225 + 510 + 1400
def test_checkout_A(self): input_1 = "A" input_2 = "AA" input_3 = "AAA" input_4 = "AAAA" assert checkout_solution.checkout(input_1) == 50 assert checkout_solution.checkout(input_2) == 100 assert checkout_solution.checkout(input_3) == 130 assert checkout_solution.checkout(input_4) == 180
def test_offers1(): offers = { 'A': [(5, 200), (3, 130), (1, 50)], } items = 'A' * 5 assert checkout(items, offers=offers, buy_offers=[]) == 200 #Lets shuffle to make sure that works items_shuffled = shuffle_str(items) assert checkout(items_shuffled, offers=offers, buy_offers=[]) == 200
def test_special_offer_individual(self): assert checkout_solution.checkout('AAA') == 130 assert checkout_solution.checkout('AAAA') == 130 + 50 assert checkout_solution.checkout("AAAAA") == 200 assert checkout_solution.checkout("AAAAAA") == 200 + 50 assert checkout_solution.checkout("AAAAAAA") == 200 + 50 * 2 assert checkout_solution.checkout('BB') == 45 assert checkout_solution.checkout('BBB') == 45 + 30 assert checkout_solution.checkout('BBBB') == 90 assert checkout_solution.checkout('FF') == 20 assert checkout_solution.checkout('FFF') == 20
def test_checkout(): assert checkout_solution.checkout("ABCD") == 115 assert checkout_solution.checkout("ABCDE") == 155 assert checkout_solution.checkout("ABCDEF") == 165 assert checkout_solution.checkout("ABCDEFG") == 185 assert checkout_solution.checkout("ABC4") == -1 assert checkout_solution.checkout("CXYZYZC") == 122 assert checkout_solution.checkout("K") == 70 assert checkout_solution.checkout("S") == 20 assert checkout_solution.checkout("Y") == 20 assert checkout_solution.checkout("ABCDEFGHIJKLMNOPQRSTUVW") == 795
def test_a_deal(): assert checkout_solution.checkout("A") == 50 assert checkout_solution.checkout("A" * 2) == 100 assert checkout_solution.checkout("A" * 3) == 130 assert checkout_solution.checkout("A" * 4) == 180 assert checkout_solution.checkout("A" * 5) == 200 assert checkout_solution.checkout("A" * 6) == 250 assert checkout_solution.checkout("A" * 7) == 300 assert checkout_solution.checkout("A" * 8) == 330 assert checkout_solution.checkout("A" * 10) == 400 assert checkout_solution.checkout("A" * 13) == 530
def test_pricing_for_a_s_special_offers(self): assert checkout_solution.checkout("A") == 50 assert checkout_solution.checkout("AA") == 100 assert checkout_solution.checkout("AAA") == 130 assert checkout_solution.checkout("AAAA") == 180 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("AAAAAAAAAA") == 400
def test_group_offer(self): assert checkout_solution.checkout("S") == 20 assert checkout_solution.checkout("X") == 17 assert checkout_solution.checkout("TY") == 40 assert checkout_solution.checkout("SXT") == 45 assert checkout_solution.checkout("ZXY") == 45 assert checkout_solution.checkout("ZTXZ") == 45 + 17 assert checkout_solution.checkout("ZTXZX") == 45 + 17 * 2 assert checkout_solution.checkout("XTXZZ") == 45 + 17 * 2 assert checkout_solution.checkout("XTXZZA") == 45 + 17 * 2 + 50 assert checkout_solution.checkout("ZZXTZXZ") == 45 * 2 + 17
def test_applying_buy_offer_is_cheaper(): buy_offers = (( BuyOfferSpec(item='A', number_required=3), BuyOfferDiscount(item="B", number_to_discount=1), ), ) items = 'A' * 6 + 'B' * 10 + 'C' * 20 assert checkout(items, offers=OFFERS, buy_offers=buy_offers) == 225 + 420 + 1400 #Lets shuffle to make sure that works items_shuffled = shuffle_str(items) assert checkout(items_shuffled, offers=OFFERS, buy_offers=buy_offers) == 225 + 420 + 1400
def test_freebies_f(): assert checkout_solution.checkout("AF") == 60 assert checkout_solution.checkout("AFF") == 70 assert checkout_solution.checkout("AFFF") == 70 assert checkout_solution.checkout("AFFFF") == 80 assert checkout_solution.checkout("AFFFFF") == 90 assert checkout_solution.checkout("AFFFFFF") == 90 assert checkout_solution.checkout("AFFFFFFF") == 100 assert checkout_solution.checkout("AFFFFFFFF") == 110 assert checkout_solution.checkout("AFFFFFFFFF") == 110
def test_checkout(self): self.assertEqual(195, checkout(self.valid_basket_1)) self.assertEqual(115, checkout(self.valid_basket_2)) self.assertEqual(0, checkout(self.valid_basket_3)) self.assertEqual(80, checkout(self.valid_basket_4)) self.assertEqual(110, checkout(self.valid_basket_5)) self.assertEqual(40, checkout(self.valid_basket_6)) self.assertEqual(155, checkout(self.valid_basket_7)) self.assertEqual(160, checkout(self.valid_basket_8)) self.assertEqual(280, checkout(self.valid_basket_9))
def test_checkout_2e_discount_with_2b_deal(self): # the saving from free item is better than price of 2 # 2 for 30 versus 2 for 45 self.assertEqual( checkout('EEBB'), 110 # ((40 * 2) + 45) + (-45 + 30) )
def test_valid_inputs(): assert checkout_solution.checkout("ABCD") == 115 assert checkout_solution.checkout("ABCDE") == 155 assert checkout_solution.checkout("AABCD") == 165 assert checkout_solution.checkout("AABBCD") == 180 assert checkout_solution.checkout("AABBBCD") == 210 assert checkout_solution.checkout("AABBBBCD") == 225 assert checkout_solution.checkout("AABBBBCDD") == 240 assert checkout_solution.checkout("AABBBBCDDE") == 280 assert checkout_solution.checkout("AABBBBCDDEF") == 290 x = list("AABBBBCDDEF") random.shuffle(x) assert checkout_solution.checkout("".join(x)) == 290
def test_applying_buy_offer_is_not_cheaper(): offers = { 'A': [(2, 75), (1, 50)], 'B': [(10, 5), (1, 60)], # a really contrived example I know 'C': [(1, 70)] } buy_offers = (( BuyOfferSpec(item='A', number_required=6), BuyOfferDiscount(item="B", number_to_discount=1), ), ) items = 'A' * 6 + 'B' * 10 + 'C' * 20 assert checkout(items, offers=offers, buy_offers=buy_offers) == 225 + 5 + 1400 #Lets shuffle to make sure that works items_shuffled = shuffle_str(items) assert checkout(items_shuffled, offers=offers, buy_offers=buy_offers) == 225 + 5 + 1400
def test_multiple_priced_skus(self): assert checkout_solution.checkout('AAA') == 130 assert checkout_solution.checkout('AAAA') == 180 assert checkout_solution.checkout('AAAAA') == 200 assert checkout_solution.checkout('AAAAAAAA') == 330 assert checkout_solution.checkout('AAAAAAAAAA') == 400 assert checkout_solution.checkout('BB') == 45 assert checkout_solution.checkout('BBB') == 75
def test_checkout_multiple_items_with_offers(self): assert checkout_solution.checkout('AAABB') == 175 assert checkout_solution.checkout('AAAABBB') == 255 assert checkout_solution.checkout('ABCDABCADA') == 295 assert checkout_solution.checkout('AAAABBBBEE') == 335 assert checkout_solution.checkout('AAAAABBBBEE') == 355 assert checkout_solution.checkout('AAAAABBBBEEFFFFFF') == 395 assert checkout_solution.checkout('AAAAABBBBEEFFFFFFSSSZZZXX') == 395 + 2 * 45 + 17 * 2
def test_pricing_for_e_s_special_offer(self): assert checkout_solution.checkout("EB") == 40 + 30 assert checkout_solution.checkout("EEB") == 40 + 40 + 0 assert checkout_solution.checkout("EE") == 40 + 40 assert checkout_solution.checkout("EEEEEB") == 40 * 5 + 0 assert checkout_solution.checkout("EEEEEBB") == 40 * 5 + 0 + 0 assert checkout_solution.checkout("EEEEEBBB") == 40 * 5 + 0 + 0 + 30 assert checkout_solution.checkout("EEEEEBBBB") == 40 * 5 + 0 + 0 + 45
def test_pricing_for_multiple_items(self): assert checkout_solution.checkout("AACAA") == 200 assert checkout_solution.checkout("AACCAA") == 220 assert checkout_solution.checkout("CAACCAA") == 240 assert checkout_solution.checkout("CAABCCAA") == 270 assert checkout_solution.checkout("CAABBCCAA") == 285 assert checkout_solution.checkout("CAADBBCCAA") == 300 assert checkout_solution.checkout("CAADBBBCCAA") == 330
def test_checkout_r2_basic_deals(self): assert checkout('AAA') == 130 assert checkout('AAAA') == 180 assert checkout('AAAAA') == 200 assert checkout('AAAAAA') == 250 assert checkout('AAAAAAAA') == 330 assert checkout('AAAAAAAAA') == 380 assert checkout('AAAAAAAAAA') == 400
def test_freebies_e(): assert checkout_solution.checkout("ABCDE") == 155 assert checkout_solution.checkout("ABCDEE") == 165 assert checkout_solution.checkout("ACDEE") == 165 assert checkout_solution.checkout("ABBCDEE") == 195 assert checkout_solution.checkout("ABCDEEE") == 205 assert checkout_solution.checkout("ABCDEEEE") == 245
def test_pricing_for_single_item(self): assert checkout_solution.checkout("A") == 50 assert checkout_solution.checkout("B") == 30 assert checkout_solution.checkout("C") == 20 assert checkout_solution.checkout("D") == 15 assert checkout_solution.checkout("E") == 40 assert checkout_solution.checkout("F") == 10
def test_pricing_for_one_item(self): assert checkout_solution.checkout("B") == 30 assert checkout_solution.checkout("BB") == 45 assert checkout_solution.checkout("BBB") == 75 assert checkout_solution.checkout("BBBB") == 90 assert checkout_solution.checkout("BBBBB") == 120 assert checkout_solution.checkout("BBBBBB") == 135
def test_pricing_for_f_s_special_offer(self): assert checkout_solution.checkout("F") == 10 assert checkout_solution.checkout("FF") == 20 assert checkout_solution.checkout("FFF") == 20 assert checkout_solution.checkout("FFFF") == 30 assert checkout_solution.checkout("FFFFF") == 40 assert checkout_solution.checkout("FFFFFF") == 40
def test_checkout_group_offer(self): assert checkout_solution.checkout('SSS') == 45 assert checkout_solution.checkout('STX') == 45 assert checkout_solution.checkout('TXY') == 45 assert checkout_solution.checkout('XYZ') == 45 assert checkout_solution.checkout('SSSXX') == 45 + 17 * 2 assert checkout_solution.checkout('SSSZZZXX') == 2 * 45 + 17 * 2
def test_individual_item(self): assert checkout_solution.checkout('A') == 50 assert checkout_solution.checkout('B') == 30 assert checkout_solution.checkout('C') == 20 assert checkout_solution.checkout('D') == 15 assert checkout_solution.checkout('E') == 40 assert checkout_solution.checkout('F') == 10
def test_new_items(self): assert checkout_solution.checkout('H' * 16) == 135 assert checkout_solution.checkout('H' * 16 + 'V' * 3 + 'U' * 5 + 'R' * 3 + 'Q' * 3) == 635 assert checkout_solution.checkout('G' * 10) == 200 assert checkout_solution.checkout('K' * 5) == 310 assert checkout_solution.checkout('N' * 3 + 'M' * 3) == 150 assert checkout_solution.checkout('P' * 11) == 450
def test_group_deal(): assert checkout_solution.checkout("ST") == 40 assert checkout_solution.checkout("STY") == 45 assert checkout_solution.checkout("STYST") == 85 assert checkout_solution.checkout("STYSTY") == 90 # the more expensive products are selected in deal with priority assert checkout_solution.checkout("STYZ") == 65 assert checkout_solution.checkout("STXZ") == 62
def test_checkout(self): test_vector = [ ('A', 50), ('123', -1), ('AAAA', 180), ('AAAAA', 200), ('AAAAAA', 250), ('A' * 9, 380), ('EEEEEBB', 200), ('AAABB', 175), ('AABCD', 165), ('F' * 6, 40), ('STXYZ', 45 + 17 + 20), ('ABCDEFGHIJKLMNOPQRSTUVWXYZ', 853 - 21 - 20 - 20 + 45), ('ZZXXX', 45 + 17 * 2), ('STXSTX', 90), ("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ", 1602), ("LGCKAQXFOSKZGIWHNRNDITVBUUEOZXPYAVFDEPTBMQLYJRSMJCWH", 1602), ] for skus, expected in test_vector: self.assertEqual(checkout(skus), expected)
def test_combined(self): assert checkout_solution.checkout('ABCD') == 115 assert checkout_solution.checkout('ABCBD') == 120
def test_special_offers(self): assert checkout_solution.checkout('AAA') == 130 assert checkout_solution.checkout('BB') == 45 assert checkout_solution.checkout('AAAA') == 180 assert checkout_solution.checkout('AAAAA') == 230 assert checkout_solution.checkout('AAAAAA') == 260