def test_pub_doesnt_serve_at_or_above_50_drunkenness(self): the_chanter = Pub("The Chanter", 100.00) a_drunk = Customer("Jarrod", 75.00, 64, 50) the_chanter.add_drink(self.drink_2) the_chanter.serve(a_drunk, self.drink_2) self.assertEqual(1, the_chanter.stock_level(self.drink_2)) self.assertEqual(75.00, a_drunk.wallet) self.assertEqual(50, a_drunk.drunkenness) self.assertEqual(100.00, the_chanter.till)
def test_pub_doesnt_serve_if_cannot_afford(self): the_chanter = Pub("The Chanter", 100.00) poor_customer = Customer("Ally", 0.00, 32, 0) the_chanter.add_drink(self.drink_2) the_chanter.serve(poor_customer, self.drink_2) self.assertEqual(1, the_chanter.stock_level(self.drink_2)) self.assertEqual(0, poor_customer.wallet) self.assertEqual(0, poor_customer.drunkenness) self.assertEqual(100.00, the_chanter.till)
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("Kings Head", 1000) def test_pub_has_name(self): self.assertEqual("Kings Head", self.pub.name) def test_pub_has_money(self): self.assertEqual(1000, self.pub.cash) def test_has_drinks(self): drink1 = Drink("Fosters", 10) self.pub.add_drink(drink1) self.assertEqual(1, len(self.pub.drinks))
class TestPub(unittest.TestCase): def setUp(self): # this sets up the list with two list items self.drink_1 = Drink("Brew Dog", 5) self.drink_2 = Drink("Dolce Banana", 15) # this says that the two items go in the list drinks = [self.drink_1, self.drink_2] # this gives values to the parameters to Class pub self.pub = Pub("The Prancing Pony", 100.00, drinks) def test_pub_has_name(self): # this checks if the pub has a name self.assertEqual("The Prancing Pony", self.pub.name) def test_does_till_have_cash(self): # this checks if the pub has cash self.assertEqual(100.00, self.pub.till) def test_can_add_money(self): # this checks if the pub can have money added self.pub.add_money(10.00) self.assertEqual(110.00, self.pub.till) def test_pub_stock_count(self): # this checks if the pub has 2 in its list self.assertEqual(2, self.pub.drink_count()) def test_can_add_drink_to_stock(self): # this sets up a new drink with its price new_drink = Drink("White Russian", 10) # this calls the add_drink method from pub.py and adds the drink assigned to new_drink self.pub.add_drink(new_drink) # this checks if the list now has three items, the 2 in the list and the 1 added self.assertEqual(3, self.pub.drink_count()) def test_can_find_drink_by_name(self): # this calls the find_drink_by_name method from pub.py and checking the drinks in the list self.pub.find_drink_by_name(self.drink_1) # this checks the name of the drink against name in the list self.assertEqual("Brew Dog", self.drink_1.name) def test_sell_drink_to_customer(self): customer = Customer("Michael Sinclair", 1000) self.pub.sell_drink_to_customer("Brew Dog", customer) # don't need 'self'.customer because customer is an instance in this method self.assertEqual(995, customer.wallet) self.assertEqual(105, self.pub.till)
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())
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("Ox", 100) self.customer = Customer("Jenny", 100) self.drink_beer = Drink("Beer", 3) self.drink_wine = Drink("Wine", 4) self.drink_cider = Drink("Cider", 3) self.pub.stock_drink = [ self.drink_beer, self.drink_wine, self.drink_cider ] def test_pub_has_name(self): self.assertEqual("Ox", self.pub.name) def test_has_till(self): self.assertEqual(100, self.pub.till) def test_add_drink(self): self.drink_soft = Drink("Soda", 1) self.pub.add_drink(self.drink_soft) self.assertEqual(4, self.pub.stock_count()) def test_remove_drink(self): self.pub.remove_drink(self.drink_cider) self.assertEqual(2, self.pub.stock_count()) def test_increase_till(self): self.pub.increase_till(self.drink_beer) self.assertEqual(103, self.pub.till) def test_sell_drink(self): self.pub.sell_drink(self.drink_wine, self.customer) self.assertEqual(96, self.customer.wallet) self.assertEqual(1, len(self.customer.drinks)) self.assertEqual(104, self.pub.till) self.assertEqual(2, self.pub.stock_count())
class TestPub(unittest.TestCase): def setUp(self): self.drink_1 = Drink("beer", 2.00) self.drink_2 = Drink("wine", 3.00) self.drink_3 = Drink("gin", 4.00) self.pub = Pub("The Prancing Pony", 100.00) self.customer = Customer("Frodo", 10.00) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.name) def test_pub_has_till(self): self.assertEqual(100.00, self.pub.till) def test_pub_can_add_drinks(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.drink_count()) def test_pub_cannot_serve_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_2) self.pub.serve(self.customer, self.drink_1) self.assertEqual(8.00, self.customer.wallet) self.assertEqual(102.00, self.pub.till) self.assertEqual(1, self.pub.drink_count()) def test_pub_cannot_serve_unstocked_drink(self): self.pub.add_drink(self.drink_1) self.pub.serve(self.customer, self.drink_2) self.assertEqual(10.00, self.customer.wallet) self.assertEqual(100.00, self.pub.till) self.assertEqual(1, self.pub.drink_count()) def test_pub_does_not_serve_too_many_drinks(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_1) self.pub.serve(self.customer, self.drink_1) self.assertEqual(1, self.pub.drink_count())
class TestPub(unittest.TestCase): def setUp(self): self.pub = Pub("The Prancing Pony", 100) self.customer_1 = Customer("Ben", 10, 18, 0) self.customer_2 = Customer("Adam", 1, 12, 0) self.drink_1 = Drink("Tennents", 2, 1) self.drink_2 = Drink("wine", 4, 2) self.drink_3 = Drink("gin", 5, 3) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.pub_name) #@unittest.skip("Delete this line to run the test") def test_pub_has_money(self): self.assertEqual(100, self.pub.till) #@unittest.skip("Delete this line to run the test") def test_pub_has_drinks(self): self.assertEqual(0, self.pub.stock_count()) def test_pub_can_add_drinks(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.stock_count()) #@unittest.skip("Delete this line to run the test") def test_customer_has_money(self): self.assertEqual( True, self.pub.check_customer_wallet(self.customer_1, self.drink_1)) #@unittest.skip("Delete this line to run the test" def test_customer_has_money(self): self.assertEqual( False, self.pub.check_customer_wallet(self.customer_2, self.drink_1)) def test_customer_money_reduced(self): self.assertEqual( 8, self.pub.take_customer_money(self.customer_1, self.drink_1)) def test_add_money_to_till(self): self.assertEqual(102, self.pub.add_to_till(self.customer_1, self.drink_1)) def test_customer_id(self): self.assertEqual(True, self.pub.age_id(self.customer_1)) def test_customer_id(self): self.assertEqual(False, self.pub.age_id(self.customer_2)) def test_customer_drunk(self): self.assertEqual( 1, self.pub.get_customer_drunk(self.customer_1, self.drink_1)) def test_pub_can_serve_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_2) self.pub.serve(self.customer_1, self.drink_1) self.assertEqual(8.00, self.customer.wallet) self.assertEqual(102.00, self.pub.till) self.assertEqual(1, self.pub.drink_count())
class TestPub(unittest.TestCase): def setUp(self): self.drink_1 = Drink("beer", 2.00, 5) self.drink_2 = Drink("wine", 3.00, 10) self.drink_3 = Drink("gin", 4.00, 30) self.pub = Pub("The Prancing Pony", 100.00) self.customer_1 = Customer("Frodo", 10.00, 28, 0) self.customer_2 = Customer("Merry", 15.00, 17, 0) self.customer_3 = Customer("Pippin", 100.00, 28, 0) def test_pub_has_name(self): self.assertEqual("The Prancing Pony", self.pub.name) def test_pub_has_till(self): self.assertEqual(100.00, self.pub.till) def test_pub_stock_value_starts_at_0(self): self.assertEqual(0, self.pub.stock_value()) def test_stock_level_0_if_drink_not_in_stock(self): self.assertEqual(0, self.pub.stock_level(self.drink_3)) def test_pub_can_add_drink(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.stock_level(self.drink_1)) self.assertEqual(2.00, self.pub.stock_value()) def test_pub_has_stock_value(self): self.pub.add_drink(self.drink_1) self.assertEqual(2.00, self.pub.stock_value()) def test_pub_can_get_stock_level(self): self.pub.add_drink(self.drink_1) self.assertEqual(1, self.pub.stock_level(self.drink_1)) def test_pub_can_add_multiple_of_same_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_1) self.assertEqual(2, self.pub.stock_level(self.drink_1)) self.assertEqual(4.00, self.pub.stock_value()) def test_pub_cannot_serve_drink(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_2) self.pub.serve(self.customer_1, self.drink_1) self.assertEqual(8.00, self.customer_1.wallet) self.assertEqual(102.00, self.pub.till) self.assertEqual(0, self.pub.stock_level(self.drink_1)) def test_pub_cannot_serve_unstocked_drink(self): self.pub.add_drink(self.drink_1) self.pub.serve(self.customer_1, self.drink_2) self.assertEqual(10.00, self.customer_1.wallet) self.assertEqual(100.00, self.pub.till) self.assertEqual(1, self.pub.stock_level(self.drink_1)) self.assertEqual(0, self.pub.stock_level(self.drink_2)) def test_pub_does_not_serve_too_many_drinks(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_1) self.pub.serve(self.customer_1, self.drink_1) self.assertEqual(1, self.pub.stock_level(self.drink_1)) def test_pub_cannot_serve_stock_runs_out(self): self.pub.add_drink(self.drink_3) self.pub.serve(self.customer_3, self.drink_3) self.pub.serve(self.customer_1, self.drink_3) self.assertEqual(0, self.pub.stock_level(self.drink_3)) self.assertEqual(10.00, self.customer_1.wallet) self.assertEqual(0, self.customer_1.drunkenness) self.assertEqual(104.00, self.pub.till) def test_pub_restocking(self): self.pub.add_drink(self.drink_1) self.pub.add_drink(self.drink_1) self.pub.serve(self.customer_1, self.drink_1) self.pub.add_drink(self.drink_1) self.assertEqual(2, self.pub.stock_level(self.drink_1)) def test_customer_is_old_enough__returns_true(self): self.assertEqual(True, self.pub.customer_is_old_enough(self.customer_1)) def test_customer_is_old_enough__returns_false(self): self.assertEqual(False, self.pub.customer_is_old_enough(self.customer_2)) def test_customer_too_drunk__returns_false(self): self.assertEqual(False, self.pub.customer_too_drunk(self.customer_1)) def test_customer_too_drunk__returns_true(self): a_drunk = Customer("Keith", 75.00, 64, 50) self.assertEqual(True, self.pub.customer_too_drunk(a_drunk)) def test_can_serve__customer_old_enough_returns_true(self): self.pub.add_drink(self.drink_2) self.assertEqual(True, self.pub.can_serve(self.customer_1, self.drink_2)) def test_can_serve__customer_not_old_enough_returns_false(self): self.pub.add_drink(self.drink_2) self.assertEqual(False, self.pub.can_serve(self.customer_2, self.drink_2)) def test_can_serve__customer_not_too_drunk_returns_true(self): self.pub.add_drink(self.drink_2) self.assertEqual(True, self.pub.can_serve(self.customer_3, self.drink_2)) def test_can_serve__customer_too_drunk__returns_false(self): a_drunk = Customer("Jack", 75.00, 64, 60) self.pub.add_drink(self.drink_2) self.assertEqual(False, self.pub.can_serve(a_drunk, self.drink_2)) def test_can_serve__customer_can_afford_drink__returns_true(self): self.pub.add_drink(self.drink_2) self.assertEqual(True, self.pub.can_serve(self.customer_1, self.drink_2)) def test_can_serve__customer_cannot_afford_drink__returns_false(self): poor_customer = Customer("Ally", 0.00, 32, 0) self.pub.add_drink(self.drink_2) self.assertEqual(False, self.pub.can_serve(poor_customer, self.drink_2)) def test_can_serve__drink_in_stock__returns_true(self): self.pub.add_drink(self.drink_3) self.assertEqual(True, self.pub.can_serve(self.customer_3, self.drink_3)) def test_can_serve__drink_not_in_stork__returns_false(self): self.pub.add_drink(self.drink_2) self.assertEqual(False, self.pub.can_serve(self.customer_3, self.drink_3)) def test_pub_checks_age__serves_over_18(self): self.pub.add_drink(self.drink_2) self.pub.serve(self.customer_1, self.drink_2) self.assertEqual(7.00, self.customer_1.wallet) self.assertEqual(103.00, self.pub.till) def test_pub_checks_age__doesnt_serve_underage(self): self.pub.add_drink(self.drink_2) self.pub.serve(self.customer_2, self.drink_2) self.assertEqual(15.00, self.customer_2.wallet) self.assertEqual(100.00, self.pub.till) def test_pub_doesnt_serve_at_or_above_50_drunkenness(self): the_chanter = Pub("The Chanter", 100.00) a_drunk = Customer("Jarrod", 75.00, 64, 50) the_chanter.add_drink(self.drink_2) the_chanter.serve(a_drunk, self.drink_2) self.assertEqual(1, the_chanter.stock_level(self.drink_2)) self.assertEqual(75.00, a_drunk.wallet) self.assertEqual(50, a_drunk.drunkenness) self.assertEqual(100.00, the_chanter.till) def test_pub_doesnt_serve_if_cannot_afford(self): the_chanter = Pub("The Chanter", 100.00) poor_customer = Customer("Ally", 0.00, 32, 0) the_chanter.add_drink(self.drink_2) the_chanter.serve(poor_customer, self.drink_2) self.assertEqual(1, the_chanter.stock_level(self.drink_2)) self.assertEqual(0, poor_customer.wallet) self.assertEqual(0, poor_customer.drunkenness) self.assertEqual(100.00, the_chanter.till)