Пример #1
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Prancing Pony", 100.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_add_cash_to_till(self):
        self.pub.add_cash_to_till(3.00)
        self.assertEqual(103.00, self.pub.till)

    def test_check_over_age_true(self):
        customer = Customer("Colin", 20.00, 25)
        customer_is_old_enough = self.pub.check_age(customer.age)
        self.assertEqual(True, customer_is_old_enough)

    def test_check_over_age_false(self):
        customer = Customer("Ed", 20.00, 17)
        customer_is_old_enough = self.pub.check_age(customer.age)
        self.assertEqual(False, customer_is_old_enough)

    def test_customer_can_buy_drink(self):
        customer = Customer("Colin", 20.00, 25)
        drink = Drink("Tennants", 3.00, 2)
        self.pub.customer_can_buy_drink(drink, customer)
        self.assertEqual(3.00, drink.price)
        self.assertEqual(17.00, customer.wallet)
        self.assertEqual(103.00, self.pub.till)
Пример #2
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Rusty Screw", 100)
        self.customer = Customer("Jack Sparrow", 1000, 20)
        self.drink = Drink("Rum", 5, 2)
        self.drink_2 = Drink("Rum n coke", 7, 5)
        self.food = Food("Fish", 10, 1)

    def test_has_name(self):
        self.assertEqual("The Rusty Screw", self.pub.name)

    def test_has_till(self):
        self.assertEqual(100, self.pub.till)

    def test_can_increase(self):
        self.pub.increase_till(100)
        self.assertEqual(200, self.pub.till)

    def test_can_buy_drink(self):
        self.pub.sell_customer_drink(self.customer, self.drink)
        self.assertEqual(105, self.pub.till)
        self.assertEqual(995, self.customer.wallet)

    def test_check_cust_is_over18(self):
        is_true = self.pub.check_age(self.customer)
        self.assertEqual(True, is_true)

    def test_check_cust_is_under18(self):
        self.customer_2 = Customer("Billy the kid", 500, 17)
        is_false = self.pub.check_age(self.customer_2)
        self.assertEqual(False, is_false)

    def test_check_customer_is_getting_smashed(self):
        self.pub.sell_customer_drink(self.customer, self.drink)
        self.assertEqual(2, self.customer.drunkenness)

    def test_if_customer_is_too_drunk(self):
        self.pub.sell_customer_drink(self.customer, self.drink_2)
        can_buy = self.pub.sell_customer_drink(self.customer, self.drink)
        self.assertEqual(False, can_buy)

    def test_food_reducing_drunkenness(self):
        self.pub.sell_customer_drink(self.customer, self.drink)
        self.pub.sell_customer_food(self.customer, self.food)
        self.assertEqual(1, self.customer.drunkenness)

    def test_drinks_list_length(self):
        self.pub.drinks_list.append(self.drink)
        self.pub.drinks_list.append(self.drink_2)
        list_len = len(self.pub.drinks_list)
        self.assertEqual(2, list_len)

    def test_stock_value(self):
        self.pub.drinks_list.append(self.drink)
        self.pub.drinks_list.append(self.drink_2)
        self.pub.incease_stock_value(self.pub.drinks_list)
        total = self.pub.stock_value
        self.assertEqual(12, total)
Пример #3
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Prancing Pony", 100.00)

    def test_pub_has_name(self):
        self.assertEqual("The Prancing Pony", self.pub.name)

    def test_increase_till(self):
        drinks = Drinks("Wine", 3.00, 1)
        self.pub.increase_till(drinks)
        self.assertEqual(103.00, self.pub.till)

    def test_customer_age__return_False(self):
        customer = Customer("Keith", 20.00, 17, 0)
        self.assertEqual(False, self.pub.check_age(customer))

    def test_customer_age__return_True(self):
        customer = Customer("Jane", 20.00, 19, 0)
        self.assertEqual(True, self.pub.check_age(customer))

    # def test_drink_transaction_True(self):
    #     customer = Customer("Jane", 20.00, 19, 0)
    #     drinks = Drinks("Wine", 3.00, 1)
    #     self.pub.drink_transaction(customer, drinks)
    #     self.assertEqual(17.00, customer.wallet)
    #     self.assertEqual(103.00, self.pub.till)

    def test_drink_transaction_True(self):
        customer = Customer("Jane", 20.00, 19, 0)
        drinks = Drinks("Wine", 3.00, 1)
        self.pub.drink_transaction(customer, drinks)
        self.assertEqual(17.00, customer.wallet)
        self.assertEqual(103.00, self.pub.till)

    def test_drink_transaction_False(self):
        customer = Customer("Bob", 20.00, 40, 11)
        drinks = Drinks("Wine", 3.00, 1)
        self.pub.drink_transaction(customer, drinks)
        self.assertEqual(20.00, customer.wallet)
        self.assertEqual(100.00, self.pub.till)

    def test_sober_enough__False(self):
        customer = Customer("Bob", 20.00, 40, 11)
        self.assertEqual(False, self.pub.sober_enough(customer))

    def test_sober_enough__True(self):
        customer = Customer("Jack", 20.00, 21, 8)
        self.assertEqual(True, self.pub.sober_enough(customer))
Пример #4
0
class TestPub(unittest.TestCase):
    
    def setUp(self):
        self.pub = Pub('The Prancing Pony', 100.00)
        self.drink = Drink("Beer", 5.00, 6)
        self.customer = Customer("TJ", 50.00, 21)

    def test_pub_has_name(self):
        pub_name = self.pub.name
        self.assertEqual('The Prancing Pony', pub_name)

    def test_pub_has_till(self):
        pub_till = self.pub.till
        self.assertEqual(100.00, pub_till)

    def test_drink_count(self):
        count = self.pub.drinks
        self.assertEqual(0, len(count))

    def test_add_to_till(self):
        self.pub.add_to_till(self.drink)
        self.assertEqual(105.00, self.pub.till)

    def test_check_age(self):
        check = self.pub.check_age(self.customer)
        self.assertEqual('What can I get you?', check)

    def test_check_drunkenness_okay(self):
        check = self.pub.check_drunkenness(self.customer)
        self.assertEqual("Yeehaw", check)
    
    def test_check_drunkenness_too_drunk(self):
        self.customer.buy_drink(self.drink)
        check = self.pub.check_drunkenness(self.customer)
        self.assertEqual("You've had enough.", check)
Пример #5
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Prancing Pony", 100.00)
        self.customer_1 = Customer("Mark", 10.00, 33, 0)
        self.customer_2 = Customer("Andrew", 20.00, 17, 10)
        self.customer_3 = Customer("Steven", 0.00, 37, 20)
        self.drink_1 = Drink("Whisky", 5, 5, 10)
        self.drink_2 = Drink("Punk IPA", 4.50, 1, 10)
        self.food_1 = Food("Pie", 2.75, 5, 10)
        self.food_2 = Food("Crisps", 0.99, 1, 0)

    def test_pub_setup(self):
        self.assertEqual("The Prancing Pony", self.pub.name)
        self.assertEqual(100.00, self.pub.till)
        self.assertEqual([], self.pub.stock)

    def test_check_age(self):
        self.assertEqual(True, self.pub.check_age(self.customer_1))
        self.assertEqual(False, self.pub.check_age(self.customer_2))

    def test_is_customer_too_drunk(self):
        self.assertEqual(True, self.pub.is_customer_too_drunk(self.customer_3))
        self.assertEqual(False,
                         self.pub.is_customer_too_drunk(self.customer_1))

    def test_find_stock_by_name_drink(self):
        self.pub.stock.extend(
            [self.drink_1, self.drink_2, self.food_1, self.food_2])
        self.assertEqual(True, self.pub.find_stock_by_name("Whisky"))
        self.assertEqual(False, self.pub.find_stock_by_name("Crisps"))

    def test_customer_can_afford(self):
        self.assertEqual(
            True, self.pub.customer_can_afford(self.customer_1, self.drink_1))
        self.assertEqual(
            False, self.pub.customer_can_afford(self.customer_3, self.drink_1))

    def test_remove_funds_from_wallet(self):
        self.assertEqual()
Пример #6
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Prancing Pony", 100.00, "Kronenburg")

    def test_pub_has_name(self):
        self.assertEqual("The Prancing Pony", self.pub.pub_name)

    def test_pub_has_till(self):
        self.assertEqual(100.00, self.pub.pub_till)

    def test_pub_has_drinks(self):
        self.assertEqual("Kronenburg", self.pub.pub_drink)

    def test_money_added_to_till(self):
        drink = Drink("Kronenburg", 3)
        self.assertEqual(103, self.pub.add_money_to_till(drink))
        # define function test.
        # define what result we want to see pub till = 103.
        # inside assertEqual () add integer, and function to call from pub class
        # self.pub tells the unit test to access the till in the Pub class and call the till with the value stored in Drink.

    def test_age_verification(self):
        customer = Customer("John", 20, 18)
        self.assertEqual(True, self.pub.check_age(customer))
Пример #7
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.drink_1 = Drink("Super T", 3)
        self.drink_2 = Drink("Buckfast", 5)
        self.drink_3 = Drink("Mysterious Cocktail", 4)
        self.drink_4 = Drink("House wine", 7)

        drinks = [
            self.drink_1,
            self.drink_2,
            self.drink_3,
            self.drink_4,
        ]

        self.pub = Pub("One way Tolbooth", 500, drinks)
        self.customer = Customer("Andrew Carnegie", 30, 185)

#    @unittest.skip("Delete this line to run the test")

    def test_has_pub_name(self):
        self.assertEqual("One way Tolbooth", self.pub.name)

#    @unittest.skip("Delete this line to run the test")

    def test_has_till(self):
        self.assertEqual(500, self.pub.till)

    # @unittest.skip("Delete this line to run the test")
    def test_can_sell_drink_to_customer(self):
        self.pub.check_age(self.customer)
        self.assertEqual(True, self.pub.check_age(self.customer))
        self.pub.sell_drink(self.customer, self.drink_2)
        self.assertEqual(505, self.pub.till)
        self.assertEqual(25, self.customer.wallet)

#  @unittest.skip("Delete this line to run the test")

    def test_check_age(self):
        self.pub.check_age(self.customer)
        self.assertEqual(True, self.pub.check_age(self.customer))
Пример #8
0
class TestPub(unittest.TestCase):
    def setUp(self):
        self.pub = Pub("The Prancing Pony", 100.00)
        self.drink1 = Drink("Gin and Tonic", 2.50, 3, 10)
        self.drink2 = Drink("Rum and Coke", 2.50, 2, 15)
        self.drink3 = Drink("Brandy", 4.00, 5, 8)

    def test_pub_has_name(self):
        self.assertEqual("The Prancing Pony", self.pub.name)

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

    def test_pub_drinks_collection(self):
        self.pub.drinks_stock = ["Gin and Tonic", "Rum and Coke", "Brandy"]
        self.assertEqual(3, len(self.pub.drinks_stock))

    def test_serve_drink(self):
        drink = Drink("Brandy", 4.00, 5, 8)
        self.pub.serve_drink(drink)
        self.assertEqual(104.00, self.pub.till)

    def test_check_age__true(self):
        customer = Customer("Frodo Baggins", 100.00, 50, 0)
        self.pub.check_age(customer)
        self.assertEqual(True, self.pub.check_age(customer))

    def test_check_age__false(self):
        customer = Customer("Peregrin Took", 80.00, 28, 0)
        self.pub.check_age(customer)
        self.assertEqual(False, self.pub.check_age(customer))

    def test_check_drunkenness__true(self):
        customer = Customer("Frodo Baggins", 100.00, 50, 0)
        self.pub.check_drunkenness(customer)
        self.assertEqual(True, self.pub.check_drunkenness(customer))

    def test_check_drunkenness__false(self):
        customer = Customer("Peregrin Took", 80.00, 28, 21)
        self.pub.check_drunkenness(customer)
        self.assertEqual(False, self.pub.check_drunkenness(customer))

    def test_check_stock_level(self):
        drink1 = Drink("Gin and Tonic", 2.50, 3, 10)
        self.assertEqual(10, drink1.stock_level)

    def test_check_total_stock_level(self):
        self.drinks_stock = [self.drink1, self.drink2, self.drink3]
        self.pub.check_total_stock_level(self.drinks_stock)
        self.assertEqual(33,
                         self.pub.check_total_stock_level(self.drinks_stock))

    def test_check_total_stock_price(self):
        self.drinks_stock = [self.drink1, self.drink2, self.drink3]
        self.pub.check_total_stock_price(self.drinks_stock)
        self.assertEqual(94.50,
                         self.pub.check_total_stock_price(self.drinks_stock))

    def test_serve_food(self):
        food = Food("Second Breakfast", 1.50, 2)
        self.pub.serve_food(food)
        self.assertEqual(101.50, self.pub.till)

    def test_at_the_bar__true(self):
        drink = self.drink1
        customer = Customer("Peregrin Took", 80.00, 31, 19)
        self.pub.at_the_bar(drink, customer)
        self.assertEqual(102.50, self.pub.till)

    def test_at_the_bar__false(self):
        drink = self.drink1
        customer = Customer("Peregrin Took", 80.00, 28, 21)
        self.pub.at_the_bar(drink, customer)
        self.assertEqual(100.00, self.pub.till)