class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") def test_animal_creation(self): bob = Dog("Bob") self.assertIsInstance(bob, Dog) self.assertIsInstance(bob, Animal) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) def test_animal_set_species(self): self.bob.set_species("Yorkie Poo") self.assertEqual(self.bob.species, "Yorkie Poo") def test_animal_get_species(self): self.bob.set_species("Yorkie Poo") self.bob.get_species() self.assertEqual(self.bob.species, "Yorkie Poo") def test_animal_speed(self): self.bob.set_legs(7) self.bob.walk() self.assertEqual(self.bob.speed, 1.4)
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") self.jacob = Animal("Jacob") def test_animal_creation(self): murph = Dog("Murph") self.assertIsInstance(murph, Dog) self.assertIsInstance(murph, Animal) self.assertIsInstance(self.jacob, Animal) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) def test_animal_can_get_species(self): self.assertIs(self.bob.get_species(), "Dog") def test_animal_can_set_species(self): self.bob.set_species("Poodle") self.assertIs(self.bob.species, "Poodle") def test_setting_speed(self): self.bob.set_legs(6) self.bob.walk() self.assertEqual(self.bob.speed, 1.20) def test_animal_get_name(self): self.assertEqual(self.bob.name, "Bob")
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog('Bob') def test_animal_exists(self): self.assertIsInstance(self.bob, Animal) self.assertIsInstance(self.bob, Dog) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) def test_animal_has_correct_name(self): self.bob.get_name() self.assertEqual(self.bob.name, 'Bob') def test_animal_has_correct_species(self): self.bob.set_species('C. lupus') self.assertEqual(self.bob.species.lower(), 'c. lupus') self.assertEqual(self.bob.get_species().lower(), 'c. lupus') def test_animal_returns_correct_str(self): self.assertEqual(self.bob.__str__().lower(), 'bob is a c. lupus') def test_dog_walks_at_speed(self): # creating a separate test class here because there is no "stop walking" method. self.bill = Dog('Bill') self.bill.set_legs(4) self.assertEqual(self.bill.speed, 0) self.bill.walk() self.assertEqual(self.bill.speed, (self.bill.speed + (0.2 * self.bill.legs)))
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") self.rob = Animal("Rob") def test_animal_creation(self): bob = Dog("Bob") self.assertIsInstance(bob, Animal) self.assertIsInstance(bob, Dog) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) def test_get_name(self): self.assertEqual(self.bob.get_name(), "Bob") def test_dog_walk(self): self.doggo = Dog("Doggo") self.doggo.walk() self.assertEqual(0, self.bob.speed) self.doggo.set_legs(4) self.doggo.walk() self.assertEqual(self.doggo.speed, .8) def test_animal_walk(self): self.animal = Animal() with self.assertRaises(ValueError): self.animal.walk() self.animal.set_legs(2) self.animal.walk() self.assertEqual(self.animal.speed, .2) def test_species(self): self.bob.set_species("dog") self.assertEqual(self.bob.get_species(), "dog")