# test_person.py # Walker M. White (wmw2) # October 15, 2015 """Unit test for Person class.""" import cornelltest import person def build_test_tree(): """Returns: Youngest generation Person in a complete family tree Creates a genealogical tree for testing""" # GREAT GRANDPARENTS (some unknown) # John Smith Sr. ggd1 = person.Person('John', 'Smith') ggm1 = person.Person('Pamela', 'Grey') ggm2 = person.Person('Eva', 'Brown') ggd4 = person.Person('Dan', 'O\'Reilly') ggm4 = person.Person('Heather', 'Chase') # GRANDPARENTS # John Smith Jr. gd1 = person.Person('John','Smith',ggm1,ggd1) gm1 = person.Person('Jane','Dare',ggm2,None) gd2 = person.Person('John','Evans') gm2 = person.Person('Ellen','O\'Reilly',ggd4,ggm4) # PARENTS # John Smith III d = person.Person('John','Smith',gm1,gd1) m = person.Person('Pamela','Evans',gm2,gd2) # FINAL GENERATION # John Smith IV p = person.Person('John','Smith',m,d) return p def test_num_ancestors(p): """Test num_ancestors on tree starting at p""" print 'Testing num_ancestors' cornelltest.assert_equals(11, person.num_ancestors(p)) cornelltest.assert_equals(4, person.num_ancestors(p.mom)) cornelltest.assert_equals(5, person.num_ancestors(p.dad)) cornelltest.assert_equals(0, person.num_ancestors(p.mom.dad)) def test_num_with_name(p): """Test num_with_name on tree starting at p""" print 'Testing num_with_name' cornelltest.assert_equals(5, person.num_with_name(p,'John')) cornelltest.assert_equals(2, person.num_with_name(p,'Pamela')) cornelltest.assert_equals(0, person.num_with_name(p,'Ralph')) # Script Code if __name__ == '__main__': p = build_test_tree() test_num_ancestors(p) test_num_with_name(p) print 'Module person is working properly'