Пример #1
0
 def test_1_and_a_bit_matches(self):
     basket = [
         PricedItem('soap', 150),
         PricedItem('shampoo', 200),
         PricedItem('shampoo', 200),
         PricedItem('soap', 150),
         PricedItem('shampoo', 200),
         PricedItem('toothpaste', 80),
         PricedItem('shampoo', 200),
         PricedItem('shampoo', 200)
     ]
     full_price, discounted = three_for_two('shampoo')(basket, [])
     self.assertEqual(
         sorted([
             PricedItem('soap', 150),
             PricedItem('soap', 150),
             PricedItem('toothpaste', 80),
             PricedItem('shampoo', 200),
             PricedItem('shampoo', 200)
         ]), sorted(full_price))
     self.assertEqual(
         sorted([
             MultiBuy('3 for 2', [
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200)
             ], 200, 400)
         ]), sorted(discounted))
Пример #2
0
 def test_multiple_rules(self):
     basket = [
         'soap', 'shampoo', 'shampoo', 'soap', 'shampoo', 'toothpaste',
         'shampoo', 'shampoo'
     ]
     receipt = make_receipt(
         basket, self.prices,
         [three_for_two('shampoo'),
          two_for('soap', 200)])
     self.assertEqual(
         sorted([
             PricedItem('shampoo', 200),
             PricedItem('shampoo', 200),
             PricedItem('toothpaste', 80),
             MultiBuy('2 for',
                      [PricedItem('soap', 150),
                       PricedItem('soap', 150)], 100, 200),
             MultiBuy('3 for 2', [
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200)
             ], 200, 400)
         ]), sorted(receipt.items))
     self.assertEqual(1080, receipt.total)
     self.assertEqual(300, receipt.saving)
Пример #3
0
 def test_not_triggered_no_triplets(self):
     basket = [
         PricedItem('soap', 150),
         PricedItem('shampoo', 200),
         PricedItem('toothpaste', 80)
     ]
     full_price, discounted = three_for_two('soap')(basket, [])
     self.assertFalse(discounted)
     self.assertEqual(
         sorted([
             PricedItem('soap', 150),
             PricedItem('shampoo', 200),
             PricedItem('toothpaste', 80)
         ]), sorted(full_price))
Пример #4
0
 def test_simplest(self):
     basket = [
         PricedItem('soap', 150),
         PricedItem('soap', 150),
         PricedItem('soap', 150)
     ]
     full_price, discounted = three_for_two('soap')(basket, [])
     self.assertFalse(full_price)
     self.assertEqual(
         sorted([
             MultiBuy('3 for 2', [
                 PricedItem('soap', 150),
                 PricedItem('soap', 150),
                 PricedItem('soap', 150)
             ], 150, 300)
         ]), sorted(discounted))
Пример #5
0
 def test_not_triggered_preserve_discounts(self):
     basket = [
         PricedItem('soap', 150),
         PricedItem('shampoo', 200),
         PricedItem('toothpaste', 80)
     ]
     already_discounted = [DiscountedItem('cheese', 100, 25, 75)]
     full_price, discounted = three_for_two('soap')(basket,
                                                    already_discounted)
     self.assertEqual(discounted, already_discounted)
     self.assertEqual(
         sorted([
             PricedItem('soap', 150),
             PricedItem('shampoo', 200),
             PricedItem('toothpaste', 80)
         ]), sorted(full_price))
Пример #6
0
 def test_simplest_preserve_discounts(self):
     basket = [
         PricedItem('soap', 150),
         PricedItem('soap', 150),
         PricedItem('soap', 150)
     ]
     already_discounted = [DiscountedItem('cheese', 100, 25, 75)]
     full_price, discounted = three_for_two('soap')(basket,
                                                    already_discounted)
     self.assertFalse(full_price)
     self.assertEqual(
         sorted([
             DiscountedItem('cheese', 100, 25, 75),
             MultiBuy('3 for 2', [
                 PricedItem('soap', 150),
                 PricedItem('soap', 150),
                 PricedItem('soap', 150)
             ], 150, 300)
         ]), sorted(discounted))
Пример #7
0
 def test_3_for_2_1_and_bit_matches(self):
     basket = [
         'soap', 'shampoo', 'shampoo', 'soap', 'shampoo', 'toothpaste',
         'shampoo', 'shampoo'
     ]
     receipt = make_receipt(basket, self.prices, [three_for_two('shampoo')])
     self.assertEqual(1180, receipt.total)
     self.assertEqual(200, receipt.saving)
     self.assertEqual(
         sorted([
             PricedItem('soap', 150),
             PricedItem('shampoo', 200),
             PricedItem('shampoo', 200),
             PricedItem('soap', 150),
             PricedItem('toothpaste', 80),
             MultiBuy('3 for 2', [
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200),
                 PricedItem('shampoo', 200)
             ], 200, 400)
         ]), sorted(receipt.items))