class TestCustomer(unittest.TestCase): def setUp(self): self.customer = Customer("Jack Jarvis", 1000) self.pet = Pet("Blue", "cat", "British Shorthair", 500) def test_customer_has_name(self): self.assertEqual("Jack Jarvis", self.customer.name) def test_customer_has_cash(self): self.assertEqual(1000, self.customer.cash) def test_customer_can_reduce_cash(self): self.customer.reduce_cash(500) self.assertEqual(500, self.customer.cash) def test_pets_start_at_0(self): self.assertEqual(0, self.customer.pet_count()) def test_can_add_pet(self): self.customer.add_pet(self.pet) self.assertEqual(1, self.customer.pet_count()) def test_can_get_total_pet_cost(self): self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) # Adds the same pet 3 times just to check the total keeps adding up. Not the best example self.assertEqual(1500, self.customer.get_total_value_of_pets())
class TestCustomer(unittest.TestCase): def setUp(self): self.customer = Customer("Jack Jarvis", 1000) self.pet = Pet("Blue", "cat", "British Shorthair", 500) def test_customer_has_name(self): self.assertEqual("Jack Jarvis", self.customer.name) def test_customer_has_cash(self): self.assertEqual(1000, self.customer.cash) # @unittest.skip("delete this line to run the test") def test_pets_start_at_0(self): self.assertEqual(0, self.customer.pet_count()) # @unittest.skip("delete this line to run the test") def test_can_add_pet(self): self.customer.add_pet(self.pet) self.assertEqual(1, self.customer.pet_count()) # @unittest.skip("delete this line to run the test") def test_can_get_total_pet_cost(self): self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.customer.add_pet(self.pet) self.assertEqual(1500, self.customer.get_total_value_of_pets())
def test_can_sell_pet_to_customer(self): customer = Customer("Jack Jarvis", 1000) self.pet_shop.sell_pet_to_customer("Sir Percy", customer) self.assertEqual(1, customer.pet_count()) self.assertEqual(1, self.pet_shop.stock_count()) self.assertEqual(1, self.pet_shop.pets_sold) self.assertEqual(1500, self.pet_shop.total_cash)