Ejemplo n.º 1
0
class TestCustomer(unittest.TestCase):

    def setUp(self):
        self.customer = Customer("Gordon", 100, 25)
        self.customer_2 = Customer("Lina", 100, 17)
        self.pub = Pub("The Prancing Pony", 100)
        self.drink = Drink("Tennents Lager", 5, 10)

    def test_customer_has_name(self):
        self.assertEqual("Gordon", self.customer.name)

    def test_customer_has_wallet(self):
        self.assertEqual(100, self.customer.wallet)

    def test_customer_can_buy_drink(self):
        self.customer.customer_buys_drink(self.drink, self.pub)
        self.assertEqual(95, self.customer.wallet)
        self.assertEqual(105, self.pub.till)

    def test_customer_over_18(self):
        self.assertEqual(True, self.pub.check_customer_age(self.customer.age))

    def test_customer_under_18(self):
        self.assertEqual(
            False, self.pub.check_customer_age(self.customer_2.age))
Ejemplo n.º 2
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.customer_holder = CustomerHolder
        self.pub = Pub("The Pink Truncheon", 100)

    def test_pub_has_name(self):
        self.assertEqual("The Pink Truncheon", self.pub.name)

    def test_pub_has_till(self):
        self.assertLess(0, self.pub.till)

    def test_add_drink_stock(self):
        name = "Pink Flamingo"
        price = 10000
        units = 3
        self.pub.add_drink_stock(name, price, units)
        self.assertEqual(5, len(self.pub.drinks))

    def test_find_drink_by_name(self):
        test_drink = {"name": "fosters", "price": 500, "units": 2}
        self.assertEqual(test_drink, self.pub.find_drink_by_name("fosters"))

    def test_add_money(self):
        self.pub.add_money(500)
        self.assertEqual(600, self.pub.till)

    def test_check_customer_age(self):
        customer = self.customer_holder.get_customer3()
        # self.assertEqual(False, self.pub.check_customer_age(customer))
        self.assertEqual(False, self.pub.check_customer_age(customer))
Ejemplo n.º 3
0
class TestPub(unittest.TestCase):
    def setUp(self):

        self.customer1 = Customer('Duncan', 2000, 12)
        self.customer2 = Customer('Lucinda', 1000, 21)
        self.customer3 = Customer('Dana', 5000, 18)

        drink1 = Drink("Guinness", 550)
        drink2 = Drink("Lager", 250)
        drink3 = Drink("Wine", 150)

        self.drinks = [drink1, drink2, drink3]

        self.pub = Pub("Alpaca Inn", self.drinks, 2000)

    def test_pub_has_name(self):
        self.assertEqual("Alpaca Inn", self.pub.name)

    def test_pub_has_drinks(self):
        self.assertEqual(3, len(self.drinks))

    def test_pub_has_till(self):

        self.assertEqual(2000, self.pub.till)

    def test_add_cash_to_till(self):
        self.pub.add_cash_to_till(self.drinks[0].price)
        self.assertEqual(2550, self.pub.till)

    def test_check_customer_age_pass(self):
        answer = self.pub.check_customer_age(self.customer3)
        self.assertEqual(True, answer)

    def test_check_customer_age_pass_fail(self):
        answer = self.pub.check_customer_age(self.customer1)
        self.assertEqual(False, answer)

    def test_serve_customer(self):
Ejemplo n.º 4
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("Ox", 100.00)
        self.customer_1 = Customer("David", 50.00)

        self.drink_beer = Drink("Beer", 5.00)
        self.drink_wine = Drink("Wine", 6.00)
        self.drink_gnt = Drink("Gin & Tonic", 7.50)
        self.drink_rum = Drink("Rum", 5.50)
        self.drink_coke = Drink("Coke", 0.75)
        self.drink_lemonade = Drink("Lemonade", 0.65)
        
        self.pub.menu_of_drinks = [
            self.drink_beer,
            # put the other menu items in here
        ]


    def test_pub_has_name(self):
        self.assertEqual("Ox", self.pub.name)

    def test_pub_has_cash_in_till(self):
        self.assertEqual(100.00, self.pub.cash)
    
    def test_till_transaction__add(self):
        self.pub.till_transaction(5)
        self.assertEqual(105.00, self.pub.cash)

    def test_drink_has_been_added_to_menu(self):
        self.pub.add_drink(self.drink_beer)
        self.assertEqual(2, self.pub.drink_count())

    def test_drink_has_been_removed_from_menu(self):
        self.pub.remove_drink(self.drink_beer)
        self.assertEqual(0, self.pub.drink_count())

    def test_sell_drink_to_customer(self):
        self.customer_1.add_drink_to_customer_hand(self.drink_beer)
        self.customer_1.alter_customer_wallet_amount(self.drink_beer.price)
        self.pub.till_transaction(self.drink_beer.price)
        self.pub.remove_drink(self.drink_beer)
        self.assertEqual(1, len(self.customer_1.drinks_in_hand))
        self.assertEqual(45, self.customer_1.wallet)
        self.assertEqual(105.00, self.pub.cash)
        self.assertEqual(0, self.pub.drink_count())

    def test_check_customer_age(self):
        self.assertEqual(True, self.pub.check_customer_age())