class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") def test_animal_creation(self): bob = self.bob self.assertIsInstance(bob, Animal) 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_can_set_species(self): self.bob.set_species('Dog') self.assertEqual(self.bob.species, 'Dog') def test_animal_can_get_species(self): self.bob.get_species() self.assertEqual(self.bob.species, 'Dog') def test_animal_can_walk(self): self.bob.set_legs(4) self.bob.walk() self.assertEqual(self.bob.speed, .8) def test_animal_get_name(self): self.bob.name = 'Winston' self.assertEqual(self.bob.name, 'Winston')
def test_dog_walking(self): dog = Dog("Goodboy") dog.set_legs(4) dog.walk() expected = 0.8 result = dog.speed self.assertEqual(result, expected)
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") def test_animal_creation(self): # One off instance of a created animal murph = Dog("Murph") self.assertIsInstance(murph, Dog) self.assertIsInstance(murph, Animal) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) def test_animal_can_set_species(self): self.bob.set_species(Dog("Bob")) self.assertIsInstance(self.bob.species, Dog) def test_animal_can_get_name(self): name = self.bob.get_name self.assertIsNotNone(name) def test_animal_speed(self): speed = self.bob.speed self.assertIsNotNone(speed) def test_animal_walk(self): self.bob.set_legs(1) self.bob.walk() self.assertEqual(self.bob.speed, 0.2)
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") def test_animal_creation(self): bob = Dog("Bob") #could also put = self.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_walk(self): self.bob.set_legs(4) self.bob.walk() self.assertEqual(self.bob.speed, .8) def test_animal_species(self): self.bob.set_species("basically human") self.assertIs(self.bob.species, "basically human")
def test_dog_can_walk(self): """ tests that a newly created dog object can call the walk method """ murph = Dog("Murph") murph.walk() self.assertEqual(murph.speed, 0) murph.set_legs(4) murph.walk() self.assertEqual(murph.speed, 0.8)
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") def test_animal_creation(self): # bob = Dog("Bob") murph = Dog("Murphy") self.assertIsInstance(murph, Dog) self.assertIsInstance(murph, Animal) def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) self.assertNotEqual(self.bob.legs, 12) def test_animal_can_set_species(self): # setting Bob's species as Canid self.bob.set_species("Caninae") # testing if user types in caninae in lowercase that it will still pass as true """this test passes if both values are true""" self.assertEqual(self.bob.species.lower(), "caninae") """this test passes if both values are not equal to each other""" self.assertNotEqual(self.bob.species.lower(), "caninaey") def test_animal_can_get_species(self): # Bob's species was set in line 28, so we just get his species by invoking get_species() """this tests SUCCESS - passes if both values are true""" self.assertEqual(self.bob.get_species().lower(), "caninae") """this tests FAILURE - passes if both values are not equal to each other""" self.assertNotEqual(self.bob.get_species().lower(), "poop") def test_str(self): self.assertEqual(self.bob.__str__().lower(), "bob is a caninae") self.assertNotEqual(self.bob.__str__().lower(), "Poop is a Butt") # def test_animal_walk(self): def test_setting_speed(self): #create a new instance of dog self.poopy = Dog("Poopy") self.assertEqual(self.poopy.speed, 0) self.poopy.walk() self.assertEqual(self.poopy.speed, 0.2)
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): print('set up class') # Be sure to pass in a name argument self.animal = Animal("Amy") self.dog = Dog("Pup") @classmethod def tearDownClass(self): print('tear down class') def test_animal_name(self): # Animal object has the correct name property. result = self.animal.get_name() expected = "Amy" self.assertEqual(result, expected) def test_animal(self): # The animal object is an instance of Animal. bird = Animal("bird") self.assertIsInstance(bird, Animal) def test_dog(self): # The dog object is an instance of Dog. maci = Dog("Maci") self.assertIsInstance(maci, Dog) def test_species(self): # Set a species and verify that the object property of species has the correct value. self.assertEqual(self.dog.get_species(), "Dog") self.dog.set_species("Puppers") self.assertEqual(self.dog.get_species(), "Puppers") def test_walk(self): # Invoking the walk() method sets the correct speed on the both objects. self.dog.set_legs(4) speed = self.dog.speed self.dog.walk() self.assertEqual(self.dog.speed, speed + (0.2 * self.dog.legs)) self.animal.set_legs(8) speed = self.animal.speed self.animal.walk() self.assertEqual(self.animal.speed, (speed + (0.1 * self.animal.legs)))
class TestAnimal(unittest.TestCase): # Setting up the global references for Dog and Animal @classmethod def setUpClass(self): self.bob = Dog("Bob") self.animal = Animal("Lucy", "canine") # Testing that there are instances of Dog and Animal def test_animal_creation(self): murph = Dog("Murph") self.assertIsInstance(murph, Dog) self.assertIsInstance(murph, Animal) # Testing that when we pass in a number of legs, that is the number of legs returned def test_animal_can_set_legs(self): self.bob.set_legs(6) self.assertEqual(self.bob.legs, 6) # Testing the walk calculation by passing in number of legs , then seeing if that number of legs is returned and then seeing if the speed is what we expect def test_animal_can_calc_walk(self): self.bob.set_legs(4) self.bob.walk() self.assertEqual(self.bob.legs, 4) self.assertEqual(self.bob.speed, .8) # Testing to see if the species we pass in is returned back to us def test_animal_can_set_species(self): self.animal.set_species("human") self.assertEqual(self.animal.species, "human") # The value in species was changed to human so this should return as Failed (below) # self.assertEqual(self.animal.species, "canine") # Testing to see if we are getting the species we expect def test_animal_can_get_species(self): self.animal.get_species() self.assertEqual(self.animal.species, "canine")
class TestAnimal(unittest.TestCase): @classmethod def setUpClass(self): self.bob = Dog("Bob") self.jonnie = Animal("Jonnie") def test_animal_creation(self): joe = Dog("Joe") self.assertIsInstance(joe, Dog) self.assertIsInstance(joe, Animal) self.assertIsInstance(self.jonnie, Animal) def test_animal_can_set_legs(self): murph = Dog("murph") murph.set_legs(6) self.assertEqual(murph.legs, 6) def test_animal_can_set_species(self): self.bob.set_species("Labrador") self.assertIs(self.bob.species, "Labrador") def test_animal_can_get_species(self): self.assertIs(self.bob.get_species(), "Dog") def test_animal_can_walk(self): self.bob.set_legs(6) self.bob.walk() self.assertEqual(self.bob.speed, 1.2) def test_animal_name(self): self.assertEqual(self.bob.name, "Bob")
def test_dog_walking_legless(self): dog = Dog("Doggo") with self.assertRaises(ValueError): dog.walk()