class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("The prancing pony", 100) self.drink = Drink("Beer", 2, 6) self.food = Food("Burger", 3, 2) self.customer = Customer("name", 10, 21) self.underage_customer = Customer("name", 10, 16) self.pub.add_stocklist(self.drink) self.pub.add_food(self.food) def test_pub_has_name(self): self.assertEqual("The prancing pony", self.pub.name) def test_check_pub_cash(self): self.assertEqual(100, self.pub.cash) def test_pub_drink(self): self.assertEqual("Beer", self.pub.stocklist[0].name) def test_sell_drink_to_overage_customer(self): self.pub.check_drink_is_in_stock(self.drink, self.customer) self.assertEqual(6, self.customer.drunkenness) self.assertEqual(8, self.customer.wallet) self.assertEqual(102, self.pub.cash) self.assertEqual([], self.pub.stocklist) def test_sell_drink_to_underage_customer(self): self.pub.check_drink_is_in_stock(self.drink, self.underage_customer) self.pub.sell_food(self.food, self.customer) self.assertNotEqual(8, self.customer.wallet) self.assertNotEqual(102, self.pub.cash) self.assertEqual([self.drink], self.pub.stocklist) def test_buy_food(self): self.pub.check_drink_is_in_stock(self.drink, self.customer) self.pub.sell_food(self.food, self.customer) self.assertEqual(5, self.customer.wallet) self.assertEqual(105, self.pub.cash) self.assertEqual(4, self.customer.drunkenness) def test_get_total_stock_value(self): self.assertEqual(2, self.pub.check_stock())
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("The Prancing Pony", 100.00) self.stock = {"beer": 5, "wine": 7, "absinthe": 2} self.drink_1 = Drink("wine", 8, 0.12) self.drink_2 = Drink("absinthe", 8, 0.8) self.food_1 = Food("pizza", 6, 0.4) self.customer_1 = Customer("Craig", 20, 18) self.customer_2 = Customer("Jack", 20, 18) self.customer_3 = Customer("Jack", 20, 17) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.name) def test_buy_drink_customer_wallet_update(self): self.pub.update_stock(self.stock) self.customer_1.buy_drink(self.drink_1, self.pub) self.assertEqual(12, self.customer_1.wallet) def test_buy_drink_till_update(self): self.pub.update_stock(self.stock) self.customer_1.buy_drink(self.drink_1, self.pub) self.assertEqual(108, self.pub.till) def test_buy_drink_customer_over_18(self): self.pub.update_stock(self.stock) update_status = self.customer_2.buy_drink(self.drink_1, self.pub) self.assertEqual(True, update_status) def test_buy_drink_customer_under_18(self): self.pub.update_stock(self.stock) update_status = self.customer_3.buy_drink(self.drink_1, self.pub) self.assertEqual(False, update_status) def test_drunkenness_update(self): self.pub.update_stock(self.stock) self.customer_1.buy_drink(self.drink_1, self.pub) self.assertEqual(0.12, self.customer_1.drunkenness) def test_too_drunk(self): self.pub.update_stock(self.stock) customer_check = self.customer_2.buy_drink(self.drink_1, self.pub) self.assertEqual(True, customer_check) def test_not_too_drunk(self): self.pub.update_stock(self.stock) self.customer_2.buy_drink(self.drink_2, self.pub) customer_check_2 = self.customer_2.buy_drink(self.drink_2, self.pub) self.assertEqual(False, customer_check_2) self.assertEqual(12, self.customer_2.wallet) def test_customer_rejuvenate(self): self.pub.update_stock(self.stock) self.customer_2.buy_drink(self.drink_2, self.pub) self.customer_2.buy_food(self.food_1, self.pub) self.assertEqual(0.4, self.customer_2.drunkenness) def test_check_stock(self): self.pub.update_stock(self.stock) self.customer_2.buy_drink(self.drink_2, self.pub) stock = self.pub.check_stock("absinthe") self.assertEqual(1, stock)