# test_person.py # Walker M. White (wmw2) # October 15, 2013 """Unit test for genealogical class.""" import cornelltest from person import * def build_test_tree(): """Returns: Youngest generation Person Create a genealogical tree for testing""" # GREAT GRANDPARENTS (some unknown) # John Smith Sr. ggd1 = Person('John', 'Smith') ggm1 = Person('Pamela', 'Grey') ggm2 = Person('Eva', 'Brown') ggd4 = Person('Dan', 'O\'Reilly') ggm4 = Person('Heather', 'Chase') # GRANDPARENTS # John Smith Jr. gd1 = Person('John','Smith',ggm1,ggd1) gm1 = Person('Jane','Dare',ggm2,None) gd2 = Person('John','Evans') gm2 = Person('Ellen','O\'Reilly',ggd4,ggm4) # PARENTS # John Smith III d = Person('John','Smith',gm1,gd1) m = Person('Pamela','Evans',gm2,gd2) # FINAL GENERATION # John Smith IV p = Person('John','Smith',m,d) return p def test_num_ancestors(p): """Test num_ancestors on tree starting at p""" cornelltest.assert_equals(11,num_ancestors(p)) cornelltest.assert_equals(4,num_ancestors(p.mom)) cornelltest.assert_equals(5,num_ancestors(p.dad)) cornelltest.assert_equals(0,num_ancestors(p.mom.dad)) def test_num_with_name(p): """Test num_with_name on tree starting at p""" cornelltest.assert_equals(5,num_with_name(p,'John')) cornelltest.assert_equals(2,num_with_name(p,'Pamela')) cornelltest.assert_equals(0,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'