Exemplo n.º 1
0
def test_no_bulk_discount():
    cart = ShoppingCart()

    product = 'Chair'
    cart.scan(product)
    cart.scan(product)

    assert cart.total_price() == 200
Exemplo n.º 2
0
def test_buy_1_get_1_free_cushion():
    cart = ShoppingCart()

    product = 'Cushion'

    cart.scan(product)
    cart.scan(product)

    assert cart.total_price() == 25
Exemplo n.º 3
0
def test_add_multiple_products_to_cart():
    cart = ShoppingCart()

    product1 = 'Chair'
    product2 = 'Sofa'
    product3 = 'Cushion'

    cart.scan(product1)
    cart.scan(product2)
    cart.scan(product3)

    assert cart.total_price() == 625
class ShoppingCartTest(unittest.TestCase):
    def setUp(self):
        self.cart = ShoppingCart()
        self.product1 = 'Wine'  # 500
        self.product2 = 'BBQ Grill'  # 100
        self.product3 = 'Beer'  # 25

    def test_calculate_total_price_for_single_product(self):
        self.cart.scan(self.product2)
        self.assertEqual(self.cart.total_price(), 100)

    def test_calculate_total_price_for_multiple_products(self):
        self.cart.scan(self.product1)
        self.cart.scan(self.product2)
        self.cart.scan(self.product3)
        self.assertEqual(self.cart.total_price(), 625)

    def test_wine_no_bulk_discount(self):
        self.cart.scan(self.product1)
        self.cart.scan(self.product1)
        self.assertEqual(self.cart.total_price(), 1000)

    def test_wine_bulk_discount(self):
        self.cart.scan(self.product1)
        self.cart.scan(self.product1)
        self.cart.scan(self.product1)
        self.assertEqual(self.cart.total_price(), 1350)

    def test_beer_buy_one_get_one_free(self):
        self.cart.scan(self.product3)
        self.cart.scan(self.product3)
        self.assertEqual(self.cart.total_price(), 25)

    def test_discount_for_employees(self):
        self.cart.scan(self.product1)
        self.cart.scan(self.product2)
        self.assertEqual(self.cart.total_price(employee=True), 540)
Exemplo n.º 5
0
def test_calculate_total_price_for_single_product_in_cart(
        product, expected_price):
    cart = ShoppingCart()
    cart.scan(product)
    assert cart.total_price() == expected_price