Example #1
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("Ox", 100.00)
        self.customer_1 = Customer("Billy", 50.00, 18)
        self.customer_2 = Customer("Jimmy", 50.00, 16)
        self.drink_1 = Drink("Beer", 5.0, 5.5)
        self.drink_2 = Drink("Wine", 7.5, 15.0)
        self.drink_3 = Drink("Spirit", 3.5, 40.0)
        self.drink_4 = Drink("Cocktail", 10.0, 25.0)

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

    def test_pub_has_cash(self):
        self.assertEqual(100.00, self.pub.cash)

    def test_customer_has_name(self):
        self.assertEqual("Billy", self.customer_1.name)

    def test_customer_has_wallet(self):
        self.assertEqual(50.00, self.customer_1.wallet)

    def test_drink_has_name(self):
        self.assertEqual("Beer", self.drink_1.name)

    def test_drink_has_price(self):
        self.assertEqual(5.00, self.drink_1.price)

    def test_customer_buy_drink(self):
        self.customer_1.buy_drink(self.drink_1)
        self.assertEqual(45, self.customer_1.wallet)

    def test_add_drink_to_menu(self):
        self.pub.add_drink_to_menu(self.drink_1)
        self.pub.add_drink_to_menu(self.drink_2)
        self.pub.add_drink_to_menu(self.drink_3)
        self.pub.add_drink_to_menu(self.drink_4)
        self.assertEqual(4, len(self.pub.menu))

    def test_add_to_cash(self):
        self.pub.sell_drink(self.drink_1)
        self.assertEqual(105.00, self.pub.cash)

    def test_customer_has_age(self):
        self.assertEqual(18, self.customer_1.age)
        self.assertEqual(16, self.customer_2.age)

    def test_age_check_adult(self):
        self.assertEqual(True, self.pub.age_check(self.customer_1))

    def test_age_check_adult(self):
        self.assertEqual(False, self.pub.age_check(self.customer_2))
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("Dirty Dicks", 100.5)

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

    def test_pub_has_till(self):
        self.assertEqual(100.5, self.pub.till)

    def test_drink_stock_starts_empty(self):
        self.assertEqual(0, len(self.pub.drink_stock))

    def test_can_add_drink_to_drink_stock(self):
        drink = Drink("Tequilla Sunrise", 4.00, 5)
        self.pub.add_to_stock(drink)
        self.assertEqual(1, len(self.pub.drink_stock))

    def test_drink_in_drink_stock(self):
        drink = Drink("Tequilla Sunrise", 4.00, 5)
        self.pub.add_to_stock(drink)
        self.assertEqual(True, self.pub.check_if_drink_in_stock(drink))

    def test_drink_not_in_drink_stock(self):
        drink = Drink("Tequilla Sunrise", 4.00, 5)
        self.assertEqual(False, self.pub.check_if_drink_in_stock(drink))

    def test_take_customer_money(self):
        drink = Drink("Tequilla Sunrise", 4.00, 5)
        customer = Customer("Bob", 25.55)
        customer.take_customers_money(drink.price)
        self.assertEqual(21.55, customer.wallet)

    def test_can_sell_drink_to_customer(self):
        drink = Drink("Tequilla Sunrise", 4.00, 5)
        customer = Customer("Bob", 25.55)
        customer.age = 22
        self.pub.add_to_stock(drink)
        self.pub.sell_drink_to_customer(customer, drink)
        self.assertEqual(21.55, customer.wallet)
        self.assertEqual(104.5, self.pub.till)

    def test_customer_age(self):
        customer = Customer("Bob", 25.55)
        customer.age = 19
        self.assertEqual(True, self.pub.age_check(customer))

    def test_drunkness_check(self):
        customer = Customer("Bob", 25.55)
        customer.customer_drunkness = 21
        self.assertEqual(True, self.pub.drunkeness_check(customer))
Example #3
0
class TestPub(unittest.TestCase):
    
    def setUp(self):
        self.pub = Pub("Duke's Corner", 100.00)
        self.drink_1 = Drink("Tennents", 3.40, 3.5)
        self.drink_2 = Drink("Wine", 7.50, 12)
        self.customer_1 = Customer("Harrison", 22, 10.00)

        self.pub.add_drink_to_pub(self.drink_1)
        self.pub.add_drink_to_pub(self.drink_2)

    def test_pub_has_name(self):
        self.assertEqual("Duke's Corner", self.pub.name)

    def test_pub_has_money(self):
        self.assertEqual(100.00, self.pub.till)

    def test_pub_has_drinks_list(self):
        self.assertEqual(type([]),type(self.pub.drinks))

    def test_pub_has_drinks(self):
        self.assertEqual(2, len(self.pub.drinks))

    def test_add_money_to_till(self):
        self.pub.add_money_to_till(self.drink_2.price)
        self.assertEqual(107.50, self.pub.till)

    def test_remove_drink_from_pub(self):
        self.pub.remove_drink_from_pub(self.drink_1)
        self.assertEqual(1, len(self.pub.drinks))
    
    def test_sell_drink(self):
        self.pub.sell_drink(self.drink_1, self.drink_1.price, self.customer_1.age)
        self.assertEqual(1, len(self.pub.drinks))
        self.assertEqual(103.40, self.pub.till)
    
    def test_age_check(self):
        result = self.pub.age_check(self.customer_1.age)
        self.assertEqual("OK to serve", result)