示例#1
0
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)
示例#2
0
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')
示例#3
0
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")
示例#4
0
class TestAnimal(unittest.TestCase):
    @classmethod
    def setUpClass(self):
        self.bob = Dog("Bob")

    def test_animal_creation(self):
        """ tests that a new dog creation is an instance of dog and animal """
        buddy = Dog("Buddy")
        self.assertIsInstance(buddy, Dog)
        self.assertIsInstance(buddy, Animal)

    def test_getting_animal_name(self):
        """ tests that the get_name method returns the correct value """
        self.assertEqual(self.bob.get_name(), "Bob")
        self.assertNotEqual(self.bob.get_name(), "bob")
        self.assertNotEqual(self.bob.get_name(), "bill")

    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)

    def test_animal_can_walk(self):
        """ tests that a newly created animal object can walk and errors will be raised if needed """
        test_animal = Animal()
        with self.assertRaises(ValueError):
            test_animal.walk()
        test_animal.set_legs(4)
        test_animal.walk()
        self.assertEqual(test_animal.speed, .4)

    def test_animal_can_set_species(self):
        """ tests that an animal object can set its species """
        self.bob.set_species("dog")
        self.assertEqual(self.bob.species, "dog")

    def test_animal_can_get_species(self):
        """ tests that an animal object can get its species """
        self.bob.set_species("doggo")
        self.assertEqual(self.bob.get_species(), "doggo")

    def test_animal_can_set_legs(self):
        """ tests that an animal object can set its legs """
        self.bob.set_legs(6)
        self.assertEqual(self.bob.legs, 6)
示例#5
0
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)
示例#6
0
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)))
示例#7
0
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")