示例#1
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        # create a few Persons
        self.child = Person('kid', 'f')
        self.mom = Person('mom', 'f')
        self.dad = Person('dad', 'm')

        # make a deep family history
        # use dict to store people for different generations

        self.generations = 4
        self.people = people = {}
        self.root_child = Person('root_child', Gender.UNKNOWN)
        people[0] = {self.root_child}

        for i in range(1, self.generations):
            people[i] = set()

        def add_parents(child, depth, max_depth):

            if depth + 1 < max_depth:
                dad = Person(child.name + '_dad', Gender.MALE)
                mom = Person(child.name + '_mom', Gender.FEMALE)
                people[depth + 1].add(dad)
                people[depth + 1].add(mom)
                child.set_father(dad)
                child.set_mother(mom)
                add_parents(dad, depth + 1, max_depth)
                add_parents(mom, depth + 1, max_depth)

        add_parents(self.root_child, 0, self.generations)

    def test_set_mother(self):
        self.child.set_mother(self.mom)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)

        self.mom.gender = Gender.MALE
        with self.assertRaises(PersonError) as context:
            self.child.set_mother(self.mom)
        self.assertIn('is not female', str(context.exception))

    def test_set_father(self):
        self.child.set_father(self.dad)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

        self.dad.gender = Gender.FEMALE
        with self.assertRaises(PersonError) as context:
            self.child.set_father(self.dad)
        self.assertIn('is not male', str(context.exception))

    def test_add_child(self):
        self.assertNotIn(self.child, self.mom.children)
        self.mom.add_child(self.child)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)

        self.assertNotIn(self.child, self.dad.children)
        self.dad.add_child(self.child)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

    def test_add_child_error(self):
        self.dad.gender = Gender.UNKNOWN
        with self.assertRaises(PersonError) as context:
            self.dad.add_child(self.child)
        self.assertIn('cannot add child', str(context.exception))
        self.assertIn('with unknown gender', str(context.exception))

    def test_remove_father(self):
        self.child.set_father(self.dad)
        self.child.remove_father()
        self.assertNotIn(self.child, self.dad.children)
        self.assertEqual(self.child.father, None)

    def test_remove_father_error(self):
        self.child.father = None
        with self.assertRaises(PersonError) as context:
            self.child.remove_father()
        self.assertIn('father is unknown', str(context.exception))

    def test_remove_mother(self):
        self.child.set_mother(self.mom)
        self.child.remove_mother()
        self.assertNotIn(self.child, self.mom.children)
        self.assertEqual(self.child.mother, None)

    def test_remove_mother_error(self):
        self.child.mother = None
        with self.assertRaises(PersonError) as context:
            self.child.remove_mother()
        self.assertIn('mother is unknown', str(context.exception))

    def test_get_persons_name(self):
        self.assertEqual(self.child.name, Person.get_persons_name(self.child))
        self.child = None
        self.assertEqual(Person.get_persons_name(self.child), 'NA')

    def test_ancestor(self):
        check = set()
        mindepth = 1
        maxdepth = 3
        for i in range(mindepth, maxdepth + 1):
            check = check.union(self.people[i])
        self.assertCountEqual(self.root_child.ancestors(mindepth, maxdepth),
                              check)

    def test_ancestor_error(self):
        max_depth = 3
        min_depth = 5
        with self.assertRaises(PersonError) as context:
            self.root_child.ancestors(min_depth, max_depth)
        self.assertIn('less than min_depth', str(context.exception))

    def test_grandparents(self):
        check = set()
        for i in range(2, 3):
            check = check.union(self.people[i])
        self.assertCountEqual(self.root_child.grandparents(), check)

    def test_all_grandparents(self):
        check = set()
        for i in range(3, len(self.people)):
            check = check.union(self.people[i])
        self.assertCountEqual(self.root_child.all_grandparents(), check)

    def test_all_ancestors(self):
        check = set()
        for i in range(1, len(self.people)):
            check = check.union(self.people[i])
        self.assertCountEqual(self.root_child.all_ancestors(), check)
示例#2
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        # create a few Persons
        self.child = Person('kid', 'NA')
        self.mom = Person('mom', 'f')
        self.dad = Person('dad', 'm')

        self.generations = 4
        self.people = people = []
        self.root_child = Person('root_child', Gender.UNKNOWN)
        people.append(self.root_child)

        def add_parents(child, depth, max_depth):
            if depth + 1 < max_depth:
                dad = Person(child.name + '_dad', Gender.MALE)
                mom = Person(child.name + '_mom', Gender.FEMALE)
                people.append(dad)
                people.append(mom)
                child.set_father(dad)
                child.set_mother(mom)
                add_parents(dad, depth + 1, max_depth)
                add_parents(mom, depth + 1, max_depth)

        add_parents(self.root_child, 0, self.generations)
        self.head_father = self.root_child.father.father.father

    def test_person_attrs(self):
        teststr = str(self.dad)
        self.assertIn("name: dad; gender: M>", teststr)

    def test_set_mother(self):
        self.child.set_mother(self.mom)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)

    def test_set_mother_error(self):
        self.mom.gender = Gender.MALE
        with self.assertRaises(PersonError) as context:
            self.child.set_mother(self.mom)
        self.assertIn('is not female', str(context.exception))

    def test_set_father(self):
        self.child.set_father(self.dad)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

    def test_set_father_error(self):
        self.dad.gender = Gender.FEMALE
        with self.assertRaises(PersonError) as context:
            self.child.set_father(self.dad)
        self.assertIn('is not male', str(context.exception))

    def test_add_child(self):
        self.assertNotIn(self.child, self.mom.children)
        #FIXED BUG from unittests: we need to set the gender of the child too, right?
        self.child.gender = Gender.MALE
        self.mom.add_child(self.child)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)

        self.assertNotIn(self.child, self.dad.children)
        #FIXED BUG from unittests: we need to set the gender of the child too, right?
        #  might as well check both genders
        self.child.gender = Gender.FEMALE
        self.dad.add_child(self.child)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

    def test_add_child_error(self):
        #FIXED BUG from unittests: we need to set the gender of the child too, right?
        self.dad.gender = Gender.UNKNOWN
        self.child.gender = Gender.MALE
        with self.assertRaises(PersonError) as context:
            self.dad.add_child(self.child)
        self.assertIn('cannot add child', str(context.exception))
        self.assertIn('with unknown gender of parent', str(context.exception))

        #adding more tests to cover all possible cases - father set on top of father
        self.dad.gender = Gender.MALE
        self.dad.add_child(self.child)
        with self.assertRaises(PersonError) as context:
            self.dad.add_child(self.child)
        self.assertIn("already has father", str(context.exception))

        #adding more tests to cover all possible cases - mother set on top of mother
        self.mom.add_child(self.child)
        with self.assertRaises(PersonError) as context:
            self.mom.add_child(self.child)
        self.assertIn("already has mother", str(context.exception))

        #adding more tests to cover all possible cases - check for loops or impossibilities in graph
        self.root_child.gender = Gender.MALE

        #adding more tests to cover all possible cases - check for loops or impossibilities in graph
        with self.assertRaises(PersonError) as context:
            self.root_child.add_child(self.head_father)
        self.assertIn("is an ancestor of person", str(context.exception))

    def test_remove_father(self):
        self.child.set_father(self.dad)
        self.child.remove_father()
        self.assertNotIn(self.child, self.dad.children)

    def test_remove_mother(self):
        self.child.set_mother(self.mom)
        self.child.remove_mother()
        #FIXED BUG from unittests: it's self.mom, not self.mother for our test cases
        self.assertNotIn(self.child, self.mom.children)

    def test_remove_father_error(self):
        #FIXED BUG from unittests: self.child doesn't initially have any parents set
        with self.assertRaises(PersonError) as context:
            self.child.remove_father()
        self.assertIn('father not set', str(context.exception))

        self.child.set_father(self.dad)
        self.dad.children.remove(self.child)
        with self.assertRaises(PersonError) as context:
            self.child.remove_father()
        self.assertIn('father named', str(context.exception))
        self.assertIn('does not have person named', str(context.exception))
        self.assertIn('in children', str(context.exception))

    def test_remove_mother_error(self):
        with self.assertRaises(PersonError) as context:
            self.child.remove_mother()
        self.assertIn('mother not set', str(context.exception))

        self.child.set_mother(self.mom)
        self.mom.children.remove(self.child)
        with self.assertRaises(PersonError) as context:
            self.child.remove_mother()
        self.assertIn('mother named', str(context.exception))
        self.assertIn('does not have person named', str(context.exception))
        self.assertIn('in children', str(context.exception))

    def test_get_persons_name(self):
        self.assertEqual(Person.get_persons_name(self.mom), "mom")
        self.assertEqual(Person.get_persons_name(None), "NA")

    def test_grandparents(self):
        grandparents_names = set([
            Person.get_persons_name(i) for i in self.root_child.grandparents()
        ])
        true_grandparents = {
            'root_child_mom_mom', 'root_child_dad_mom', 'root_child_mom_dad',
            'root_child_dad_dad'
        }
        self.assertEqual(grandparents_names, true_grandparents)

    def test_all_grandparents(self):
        all_grandparents_names = set([
            Person.get_persons_name(i)
            for i in self.root_child.all_grandparents()
        ])
        #FIXED BUG: all grandparents returns all grandparents + great-grands, etc...
        true_all_grandparents = {
            'root_child_dad_mom_dad', 'root_child_dad_dad_dad',
            'root_child_dad_mom_mom', 'root_child_mom_dad_dad',
            'root_child_mom_dad_mom', 'root_child_mom_mom_dad',
            'root_child_mom_mom_mom', 'root_child_dad_dad_mom',
            'root_child_mom_mom', 'root_child_dad_mom', 'root_child_mom_dad',
            'root_child_dad_dad'
        }
        self.assertEqual(all_grandparents_names, true_all_grandparents)

    def test_all_ancestors(self):
        all_ancestors = set([
            Person.get_persons_name(i)
            for i in self.root_child.all_ancestors()
        ])
        true_all_ancestors = {
            'root_child_mom_dad', 'root_child_mom_dad_mom',
            'root_child_mom_mom', 'root_child_dad_dad_dad',
            'root_child_dad_mom', 'root_child_mom', 'root_child_mom_dad_dad',
            'root_child_dad_mom_dad', 'root_child_dad_dad',
            'root_child_mom_mom_mom', 'root_child_dad_mom_mom',
            'root_child_dad', 'root_child_mom_mom_dad',
            'root_child_dad_dad_mom'
        }
        self.assertEqual(all_ancestors, true_all_ancestors)

    def test_parents(self):
        parents = set(
            [Person.get_persons_name(i) for i in self.root_child.parents()])
        true_parents = {'root_child_dad', 'root_child_mom'}
        self.assertEqual(parents, true_parents)

    def test_ancestors(self):
        '''ancestors code has already been 100% covered 
        in other unittests (multiple levels and depths)'''
        pass

    def test_ancestors_error(self):
        with self.assertRaises(PersonError) as context:
            self.root_child.ancestors(min_depth=2, max_depth=1)
        self.assertIn('max_depth (1) cannot be less than min_depth (2)',
                      str(context.exception))

    def test_descendants(self):
        children = set([
            Person.get_persons_name(i) for i in self.head_father.descendants()
        ])
        true_children = {'root_child_dad_dad'}
        self.assertEqual(children, true_children)

        all_descendants = set([
            Person.get_persons_name(i)
            for i in self.head_father.descendants(min_depth=1,
                                                  max_depth=float('inf'))
        ])
        true_descendants = {
            'root_child_dad_dad', 'root_child_dad', 'root_child'
        }
        self.assertEqual(all_descendants, true_descendants)

    def test_descendants_error(self):
        with self.assertRaises(PersonError) as context:
            self.head_father.descendants(min_depth=2, max_depth=1)
        self.assertIn('max_depth (1) cannot be less than min_depth (2)',
                      str(context.exception))
class TestFamily(unittest.TestCase):
    # Function to first contruct the family tree and store the root as Shan
    def setUp(self):
        main_class = MainClass()
        self.shan = Person("Shan", MALE)
        self.obj = Person()
        commands = main_class.read_input_file(POPULATE_FAMILY_TREE_FILE)
        main_class.call_fam_funcs(self.shan,
                                  commands,
                                  populate_family_tree=True)

    def test_find_person_positive(self):
        answers_retrieved_obj = self.obj.find_person(self.shan, "Kriya")
        self.assertEqual("Kriya", answers_retrieved_obj.name)

    def test_find_person_negative(self):
        answers_retrieved_obj = self.obj.find_person(self.shan, "abc")
        self.assertEqual(None, answers_retrieved_obj)

    def test_paternal_uncles_positive(self):
        correct_answer = ['Chit', 'Ish', 'Vich']
        answers_retrieved_obj = self.obj.get_paternal_uncles(self.shan, "Jnki")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_paternal_uncles_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_paternal_uncles(
            self.shan, "Satvy")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_maternal_uncles_positive(self):
        correct_answer = ['Ahit']
        answers_retrieved_obj = self.obj.get_maternal_uncles(
            self.shan, "Lavnya")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_maternal_uncles_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_maternal_uncles(self.shan, "Vila")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_paternal_aunts_positive(self):
        correct_answer = ['Atya']
        answers_retrieved_obj = self.obj.get_paternal_aunts(self.shan, "Vasa")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_paternal_aunts_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_paternal_aunts(self.shan, "Krpi")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_maternal_aunts_positive(self):
        correct_answer = ['Tritha']
        answers_retrieved_obj = self.obj.get_maternal_aunts(
            self.shan, "Yodhan")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_maternal_aunts_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_maternal_aunts(
            self.shan, "Krithi")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_sisters_in_laws_positive(self):
        correct_answer = ['Amba', 'Lika', 'Chitra']
        answers_retrieved_obj = self.obj.get_sisters_in_law(self.shan, "Satya")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_sisters_in_laws_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_sisters_in_law(self.shan, "Jnki")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_brothers_in_laws_positive(self):
        correct_answer = ['Ahit']
        answers_retrieved_obj = self.obj.get_brothers_in_law(self.shan, "Arit")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_brothers_in_laws_negative_none(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_brothers_in_law(
            self.shan, "Chika")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_sons_positive(self):
        correct_answer = ['Chit', 'Ish', 'Vich', 'Aras']
        answers_retrieved_obj = self.obj.get_sons(self.shan, "Anga")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_sons_negative(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_sons(self.shan, "Vich")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_daughters_positive(self):
        correct_answer = ['Dritha', 'Tritha']
        answers_retrieved_obj = self.obj.get_daughters(self.shan, "Chit")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_daughters_negative(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_daughters(self.shan, "Asva")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_siblings_positive(self):
        correct_answer = ['Chit', 'Ish', 'Aras', 'Satya']
        answers_retrieved_obj = self.obj.get_siblings(self.shan, "Vich")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_siblings_negative(self):
        correct_answer = 0
        answers_retrieved_obj = self.obj.get_siblings(self.shan, "Jaya")
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_brothers_positive(self):
        correct_answer = ['Chit', 'Ish', 'Vich', 'Aras']
        person = self.obj.find_person(self.shan, "Satya")
        answers_retrieved_obj = self.obj.get_brothers(person)
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_brothers_negative(self):
        correct_answer = 0
        person = self.obj.find_person(self.shan, "Yodhan")
        answers_retrieved_obj = self.obj.get_brothers(person)
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_sisters_positive(self):
        correct_answer = ['Dritha', 'Tritha']
        person = self.obj.find_person(self.shan, "Vritha")
        answers_retrieved_obj = self.obj.get_sisters(person)
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_sisters_negative(self):
        correct_answer = 0
        person = self.obj.find_person(self.shan, "Lavnya")
        answers_retrieved_obj = self.obj.get_sisters(person)
        self.assertEqual(len(answers_retrieved_obj), correct_answer)

    def test_add_child_daughter(self):
        mother = self.obj.find_person(self.shan, "Jnki")
        self.obj.add_child(mother, Person("Rohini", FEMALE))
        correct_answer = ["Lavnya", "Rohini"]
        answers_retrieved_obj = self.obj.get_daughters(self.shan, "Jnki")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)
        father = self.obj.find_person(self.shan, "Arit")
        answers_retrieved_obj = self.obj.get_daughters(self.shan,
                                                       father.wife.name)
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_add_child_son(self):
        mother = self.obj.find_person(self.shan, "Dritha")
        self.obj.add_child(mother, Person("Arjun", MALE))
        correct_answer = ["Yodhan", "Arjun"]
        answers_retrieved_obj = self.obj.get_sons(self.shan, "Dritha")
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)
        father = self.obj.find_person(self.shan, "Jaya")
        answers_retrieved_obj = self.obj.get_sons(self.shan, father.wife.name)
        answers_retrieved_lst = list()
        for answer in answers_retrieved_obj:
            answers_retrieved_lst.append(answer.name)
        self.assertEqual(answers_retrieved_lst, correct_answer)

    def test_add_spouse_husband(self):
        wife = self.obj.find_person(self.shan, "Chika")
        husband_to_be_added = Person("Chetan", MALE)
        self.obj.add_spouse(wife, husband_to_be_added)
        husband = self.obj.find_person(self.shan, "Chetan")
        self.assertEqual(husband.name, "Chetan")

    def test_add_spouse_wife(self):
        husband = self.obj.find_person(self.shan, "Ahit")
        wife_to_be_added = Person("Deepa", FEMALE)
        self.obj.add_spouse(husband, wife_to_be_added)
        wife = self.obj.find_person(self.shan, "Deepa")
        self.assertEqual(wife.name, "Deepa")
示例#4
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        # create a Person
        self.child = Person('kid', 'NA')
        self.mom = Person('mom', 'f')
        self.dad = Person('dad', 'm')

        # make a deep family history

        self.generations = 4
        self.people = people = []
        self.root_child = Person('root_child', Gender.UNKNOWN)
        people.append(self.root_child)

        def add_parents(child, depth, max_depth):
            if depth + 1 < max_depth:
                dad = Person(child.name + '_dad', Gender.MALE)
                mom = Person(child.name + '_mom', Gender.FEMALE)
                people.append(dad)
                people.append(mom)
                child.set_father(dad)
                child.set_mother(mom)
                add_parents(dad, depth + 1, max_depth)
                add_parents(mom, depth + 1, max_depth)

        add_parents(self.root_child, 0, self.generations)

    def test_set_mother(self):
        '''Testing set_mother'''

        self.child.set_mother(self.mom)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)

        self.mom.gender = Gender.MALE
        with self.assertRaises(PersonError) as context:
            self.child.set_mother(self.mom)
        self.assertIn("is not female", str(context.exception))

    def test_set_father(self):
        '''Testing set_father'''

        self.child.set_father(self.dad)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

        self.dad.gender = Gender.FEMALE
        with self.assertRaises(PersonError) as context:
            self.child.set_father(self.dad)
        self.assertIn('is not male', str(context.exception))

    def test_remove_father(self):
        '''Testing function remove_father'''

        with self.assertRaises(Exception) as context:
            self.child.remove_father()
        self.assertIn('is not known', str(context.exception))

        self.child.set_father(self.dad)
        self.dad.children.remove(self.child)
        with self.assertRaises(Exception) as context:
            self.child.remove_father()
        self.assertIn('is not a child of father', str(context.exception))

        self.child.set_father(self.dad)
        self.child.remove_father()
        self.assertNotEqual(self.dad, self.child.father)
        self.assertNotIn(self.child, self.dad.children)

    def test_remove_mother(self):
        '''Testing function remove_mother'''

        with self.assertRaises(Exception) as context:
            self.child.remove_mother()
        self.assertTrue('is not know', str(context.exception))

        self.child.set_mother(self.mom)
        self.mom.children.remove(self.child)
        with self.assertRaises(Exception) as context:
            self.child.remove_mother()
        self.assertTrue('is not a child of mother', str(context.exception))

        self.child.set_mother(self.mom)
        self.child.remove_mother()
        self.assertNotEqual(self.mom, self.child.mother)
        self.assertNotIn(self.child,
                         self.mom.children)  # self.mom noted in setUp

    def test_add_child(self):
        ''' Testing add_child '''

        self.assertNotIn(self.child, self.mom.children)
        self.mom.add_child(self.child)
        self.assertEqual(self.child.mother, self.mom)
        self.assertIn(self.child, self.mom.children)
        self.assertNotIn(self.child, self.dad.children)
        self.dad.add_child(self.child)
        self.assertEqual(self.child.father, self.dad)
        self.assertIn(self.child, self.dad.children)

    def test_add_child_error(self):
        ''' Test add_child_error '''

        self.dad.gender = Gender.UNKNOWN
        with self.assertRaises(PersonError) as context:
            self.dad.add_child(self.child)
        self.assertIn('cannot add child',
                      str(context.exception))  # added the str to test
        self.assertIn('with unknown gender',
                      str(context.exception))  # added the str to test

    '''def test_remove_father(self):
        self.child.set_father(self.dad)
        self.child.remove_father()
        self.assertNotIn(self.child, self.dad.children)
     '''

    def test_get_persons_name(self):
        '''Testing get_persons_name '''

        self.assertEqual('root_child',
                         self.root_child.get_persons_name(self.root_child))
        self.assertEqual(Person.get_persons_name(self.child), self.child.name)
        self.assertEqual(Person.get_persons_name(None), 'NA')
        self.assertIs(Person.get_persons_name(self.child), self.child.name)
        self.assertTrue(Person.get_persons_name(self.child), self.child.name)

    def test_grandparents(self):
        '''Testing grandparents '''

        self.assertIn(self.root_child.father.father,
                      self.root_child.grandparents())
        self.assertIn(self.root_child.father.mother,
                      self.root_child.grandparents())
        self.assertIn(self.root_child.mother.father,
                      self.root_child.grandparents())
        self.assertIn(self.root_child.mother.mother,
                      self.root_child.grandparents())

    def test_all_grandparents(self):
        ''' Testing all_grandparents '''

        self.assertIn(self.root_child.father.father.father,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.father.father.mother,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.father.mother.father,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.father.mother.father,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.mother.father,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.father.father,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.father.mother,
                      self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.mother.father,
                      self.root_child.all_grandparents())

        self.assertIn(self.root_child.mother.father.father,
                      self.root_child.all_grandparents())
        self.assertIsNot(self.root_child.mother.father.father,
                         self.root_child.all_grandparents())
        self.assertIsNotNone(self.root_child.mother.father.father,
                             self.root_child.all_grandparents())
        self.assertIsNot(self.root_child, self.root_child.all_grandparents())
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.all_grandparents())

    def test_all_ancestors(self):
        ''' Testing all_ancestors '''

        self.assertNotEqual(self.root_child.father,
                            self.root_child.all_ancestors())
        self.assertIn(self.root_child.father.father.father,
                      self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.all_ancestors())
        self.assertIn(self.root_child.father.mother.mother,
                      self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother.father.mother,
                      self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother, self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother.mother,
                      self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother.father,
                      self.root_child.all_ancestors())
        self.assertIsNot(self.root_child.mother.father.father.father,
                         self.root_child.all_ancestors())
        self.assertIsNot(self.root_child.mother.mother.mother.mother,
                         self.root_child.all_ancestors())

        self.assertIn(self.root_child.father, self.root_child.all_ancestors())
        self.assertIn(self.root_child.father.father,
                      self.root_child.all_ancestors())
        self.assertNotIn(self.root_child, self.root_child.all_ancestors())
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.all_ancestors())

    def test_ancestors(self):
        ''' Testing ancestors '''

        self.assertIn(self.root_child.father, self.root_child.ancestors(1))
        self.assertIn(self.root_child.father.father,
                      self.root_child.ancestors(2))
        self.assertIn(self.root_child.father.mother,
                      self.root_child.ancestors(2))
        self.assertIn(self.root_child.mother.father,
                      self.root_child.ancestors(2))
        self.assertIn(self.root_child.mother.mother,
                      self.root_child.ancestors(2))

        self.assertIn(self.root_child.father.father.father,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.father.father.mother,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.father.mother.father,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.father.mother.mother,
                      self.root_child.ancestors(3))

        self.assertIn(self.root_child.mother.mother.father,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.mother.father.mother,
                      self.root_child.ancestors(3))
        self.assertIn(self.root_child.mother.father.mother,
                      self.root_child.ancestors(3))

        self.assertIn(self.root_child.mother, self.root_child.ancestors(1))
        self.assertIn(self.root_child.mother.mother,
                      self.root_child.ancestors(2))
        self.assertIn(self.root_child.mother.mother.mother,
                      self.root_child.ancestors(3))
        #self.assertIn(self.root_child.father.father.father.father,self.root_child.ancestors(4)) # not present
        self.assertNotIn(self.root_child.father, self.root_child.ancestors(0))

        with self.assertRaises(PersonError) as context:
            self.root_child.ancestors(min_depth=2, max_depth=1)
        self.assertIn('max_depth (1) cannot be less than min_depth (2)',
                      str(context.exception))

    def test_parent(self):
        self.assertEqual(self.root_child.father, self.root_child.father)
        self.assertEqual(self.root_child.mother, self.root_child.mother)