# create a dictionary that represents a person def createPerson(firstName,lastName,yearOfBirth): """ This function takes in the various attributes for a person and returns a dictionary with keys for first name, last name and year of birth with their respective values equal to whatever was passed to this function. """ record = {'firstName':firstName, 'lastName':lastName, 'yearOfBirth':yearOfBirth} return record def getFirstName(person): """ function that returns the first name of a person """ return person['firstName'] def getLastName(person): """ function that returns the last name of a person """ return person['lastName'] def getYearOfBirth(person): """ function that returns the year of birth of a person """ return person['yearOfBirth'] # create an instance that represents a person named John Doe john = createPerson("John", "Doe", 1945) ############### tests ################### # tests for persons defined in a non-OO manner import unittest class PersonTests(unittest.TestCase): def setUp(self): #create an instance that represents a person named John Doe self.john = createPerson("John", "Doe", 1945) #create an instance of elvis presley self.elvis = createPerson("Elvis", "Presley", 1935) def test_firstname(self): self.assertEquals("John", getFirstName(self.john)) self.assertEquals("Elvis", getFirstName(self.elvis)) def test_lastname(self): self.assertEquals("Doe", getLastName(self.john)) self.assertEquals("Presley", getLastName(self.elvis)) def test_yearofbirth(self): self.assertEquals(1945, getYearOfBirth(self.john)) self.assertEquals(1935, getYearOfBirth(self.elvis)) suite = unittest.TestLoader().loadTestsFromTestCase(PersonTests) unittest.TextTestRunner(verbosity=2).run(suite)