def test_maternal_grandmothers_sister(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) mum = Node( Person.objects.create(name='mum', gender='F', family_id=self.family.id)) grandmother = Node( Person.objects.create(name='grandmother', gender='F', family_id=self.family.id)) great_grandmother = Node( Person.objects.create(name='great_grandmother', gender='F', family_id=self.family.id)) great_aunt = Node( Person.objects.create(name='great_aunt', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, great_aunt) path.add_node(mum, RAISED_BY) path.add_node(grandmother, RAISED_BY) path.add_node(great_grandmother, RAISED_BY) path.add_node(great_aunt, RAISED) result = get_name(path) self.assertEqual(1, len(result)) self.assertEqual("Maternal Grandmother's Sister", result[0])
def test_fathers_sister(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) father = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id, birth_year=1990)) grandparent = Node( Person.objects.create(name='grandparent', gender='F', family_id=self.family.id)) aunt = Node( Person.objects.create(name='aunt', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, aunt) path.add_node(father, RAISED_BY) path.add_node(grandparent, RAISED_BY) path.add_node(aunt, RAISED) result = get_name(path) self.assertTrue("Father's Elder Sister" in result) self.assertTrue("Father's Younger Sister" in result) self.assertTrue("Father's Sister" in result)
def test_great_grandfather(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) parent = Node( Person.objects.create(name='dad', gender='O', family_id=self.family.id)) paternal_grandmother = Node( Person.objects.create(name='paternal_grandmother', gender='F', family_id=self.family.id)) great_grandfather = Node( Person.objects.create(name='great_grandfather', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, great_grandfather) path.add_node(parent, RAISED_BY) path.add_node(paternal_grandmother, RAISED_BY) path.add_node(great_grandfather, RAISED_BY) result = get_name(path) self.assertTrue('Paternal Great Grandfather' in result) self.assertTrue('Maternal Great Grandfather' in result)
def test_elder_sisters_husband(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id, birth_year=1990)) father = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id)) sister = Node( Person.objects.create(name='sister', gender='F', family_id=self.family.id, birth_year=1989)) sisters_husband = Node( Person.objects.create(name='sisters_husband', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, sisters_husband) path.add_node(father, RAISED_BY) path.add_node(sister, RAISED) path.add_node(sisters_husband, PARTNERED) result = get_name(path) self.assertTrue("Elder Sibling's Husband" in result)
def find_path(self, from_id, to_id): ''' Calculates path from one node to another ''' if from_id == to_id: return if not from_id in self.nodes or not to_id in self.nodes: return node = self.nodes[from_id] goal_node = self.nodes[to_id] paths = [] for relation_type, relation in node.relations: path = Path() path.set_goals(node, goal_node) paths.append(path) path.add_node(relation, relation_type) if path.success: self.result = path return path self.search_paths(paths)
def test_brothers_daughter(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) parent = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id)) brother = Node( Person.objects.create(name='brother', gender='M', family_id=self.family.id)) brothers_daughter = Node( Person.objects.create(name='brothers_daughter', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, brothers_daughter) path.add_node(parent, RAISED_BY) path.add_node(brother, RAISED) path.add_node(brothers_daughter, RAISED) result = get_name(path) self.assertTrue("Brother's Daughter" in result)
def test_sisters_child(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) parent = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id)) sister = Node( Person.objects.create(name='sister', gender='F', family_id=self.family.id)) sisters_child = Node( Person.objects.create(name='sisters_child', gender='O', family_id=self.family.id)) path = Path() path.set_goals(person, sisters_child) path.add_node(parent, RAISED_BY) path.add_node(sister, RAISED) path.add_node(sisters_child, RAISED) result = get_name(path) self.assertTrue("Sister's Daughter" in result) self.assertTrue("Sister's Son" in result)
def test_partners_brother(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) partner = Node( Person.objects.create(name='partner', gender='O', family_id=self.family.id)) partners_mother = Node( Person.objects.create(name='partner_mother', gender='F', family_id=self.family.id)) partners_brother = Node( Person.objects.create(name='partner_brother', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, partners_brother) path.add_node(partner, PARTNERED) path.add_node(partners_mother, RAISED_BY) path.add_node(partners_brother, RAISED) result = get_name(path) self.assertTrue("Wife's Elder Brother" in result) self.assertTrue("Wife's Younger Brother" in result) self.assertTrue("Husband's Elder Brother" in result) self.assertTrue("Husband's Younger Brother" in result)
def test_husbands_elder_sister(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) husband = Node( Person.objects.create(name='husband', gender='M', family_id=self.family.id, birth_year=1990)) husbands_mother = Node( Person.objects.create(name='husbands_mother', gender='F', family_id=self.family.id)) husbands_sister = Node( Person.objects.create(name='husbands_sister', gender='F', family_id=self.family.id, birth_year=1988)) path = Path() path.set_goals(person, husbands_sister) path.add_node(husband, PARTNERED) path.add_node(husbands_mother, RAISED_BY) path.add_node(husbands_sister, RAISED) result = get_name(path) self.assertTrue("Husband's Elder Sister" in result)
def test_fathers_younger_brother(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) father = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id, birth_year=1990)) grandparent = Node( Person.objects.create(name='grandparent', gender='F', family_id=self.family.id)) uncle = Node( Person.objects.create(name='uncle', gender='M', family_id=self.family.id, birth_year=1991)) path = Path() path.set_goals(person, uncle) path.add_node(father, RAISED_BY) path.add_node(grandparent, RAISED_BY) path.add_node(uncle, RAISED) result = get_name(path) self.assertTrue("Father's Younger Brother" in result) self.assertTrue("Father's Brother" in result)
def test_childs_mother_in_law(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) child = Node( Person.objects.create(name='child', gender='O', family_id=self.family.id)) childs_partner = Node( Person.objects.create(name='childs_partner', gender='O', family_id=self.family.id)) childs_partners_mother = Node( Person.objects.create(name='childs_partners_mother', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, childs_partners_mother) path.add_node(child, RAISED) path.add_node(childs_partner, PARTNERED) path.add_node(childs_partners_mother, RAISED_BY) result = get_name(path) self.assertTrue("Child's Mother In Law" in result)
def test_paternal_great_grandfather(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) dad = Node( Person.objects.create(name='dad', gender='M', family_id=self.family.id)) paternal_grandmother = Node( Person.objects.create(name='paternal_grandmother', gender='F', family_id=self.family.id)) paternal_great_grandfather = Node( Person.objects.create(name='paternal_great_grandfather', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, paternal_great_grandfather) path.add_node(dad, RAISED_BY) path.add_node(paternal_grandmother, RAISED_BY) path.add_node(paternal_great_grandfather, RAISED_BY) result = get_name(path) self.assertEqual('Paternal Great Grandfather', result[0])
def test_step_grandparent(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) mother = Node( Person.objects.create(name='mother', gender='F', family_id=self.family.id)) grandparent = Node( Person.objects.create(name='grandparent', gender='F', family_id=self.family.id)) step_grandparent = Node( Person.objects.create(name='step_grandparent', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, step_grandparent) path.add_node(mother, RAISED_BY) path.add_node(grandparent, RAISED_BY) path.add_node(step_grandparent, PARTNERED) result = get_name(path) self.assertEqual([], result)
def test_mothers_sisters_husband(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) mother = Node( Person.objects.create(name='mother', gender='F', family_id=self.family.id)) grandmother = Node( Person.objects.create(name='grandmother', gender='F', family_id=self.family.id)) aunt = Node( Person.objects.create(name='aunt', gender='F', family_id=self.family.id)) aunt_husband = Node( Person.objects.create(name='aunt husband', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, aunt_husband) path.add_node(mother, RAISED_BY) path.add_node(grandmother, RAISED_BY) path.add_node(aunt, RAISED) path.add_node(aunt_husband, PARTNERED) result = get_name(path) self.assertTrue("Mother's Sister's Husband" in result)
def test_male_great_grandchild_non_other_lineage(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) child = Node( Person.objects.create(name='child', gender='O', family_id=self.family.id)) grandchild = Node( Person.objects.create(name='grandchild', gender='M', family_id=self.family.id)) great_grandchild = Node( Person.objects.create(name='great_grandchild', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, great_grandchild) path.add_node(child, RAISED) path.add_node(grandchild, RAISED) path.add_node(great_grandchild, RAISED) result = get_name(path) self.assertTrue("Son's Grandson" in result) self.assertTrue("Daughter's Grandson" in result)
def test_younger_sibling(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id, birth_year=1982)) dad = Node( Person.objects.create(name='dad', gender='M', family_id=self.family.id)) sibling = Node( Person.objects.create(name='sibling', gender='O', family_id=self.family.id, birth_year=1990)) path = Path() path.set_goals(person, sibling) path.add_node(dad, RAISED_BY) path.add_node(sibling, RAISED) result = get_name(path) self.assertTrue("Younger Brother" in result) self.assertTrue("Younger Sister" in result)
def test_fathers_elder_sisters_husband(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) father = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id, birth_year=1992)) grandmother = Node( Person.objects.create(name='grandmother', gender='F', family_id=self.family.id)) aunt = Node( Person.objects.create(name='aunt', gender='F', family_id=self.family.id, birth_year=1990)) aunt_husband = Node( Person.objects.create(name='aunt husband', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, aunt_husband) path.add_node(father, RAISED_BY) path.add_node(grandmother, RAISED_BY) path.add_node(aunt, RAISED) path.add_node(aunt_husband, PARTNERED) result = get_name(path) self.assertEqual(["Father's Elder Sister's Husband"], result)
def test_maternal_younger_cousin(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id, birth_year=2000)) mother = Node( Person.objects.create(name='mother', gender='F', family_id=self.family.id)) grandmother = Node( Person.objects.create(name='grandmother', gender='F', family_id=self.family.id)) aunt = Node( Person.objects.create(name='aunt', gender='F', family_id=self.family.id)) cousin = Node( Person.objects.create(name='aunt husband', gender='O', family_id=self.family.id, birth_year=2005)) path = Path() path.set_goals(person, cousin) path.add_node(mother, RAISED_BY) path.add_node(grandmother, RAISED_BY) path.add_node(aunt, RAISED) path.add_node(cousin, RAISED) result = get_name(path) self.assertTrue("Maternal Younger Male Cousin" in result) self.assertTrue("Maternal Younger Female Cousin" in result)
def test_wifes_younger_sister(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) wife = Node( Person.objects.create(name='wife', gender='F', family_id=self.family.id, birth_year=1990)) wifes_mother = Node( Person.objects.create(name='wifes_mother', gender='F', family_id=self.family.id)) wifes_sister = Node( Person.objects.create(name='wifes_sister', gender='F', family_id=self.family.id, birth_year=1998)) path = Path() path.set_goals(person, wifes_sister) path.add_node(wife, PARTNERED) path.add_node(wifes_mother, RAISED_BY) path.add_node(wifes_sister, RAISED) result = get_name(path) self.assertTrue("Wife's Younger Sister" in result)
def test_siblings_partner_(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) parent = Node( Person.objects.create(name='father', gender='M', family_id=self.family.id)) sibling = Node( Person.objects.create(name='sibling', gender='O', family_id=self.family.id)) siblings_partner = Node( Person.objects.create(name='siblings_partner', gender='O', family_id=self.family.id)) path = Path() path.set_goals(person, siblings_partner) path.add_node(parent, RAISED_BY) path.add_node(sibling, RAISED) path.add_node(siblings_partner, PARTNERED) result = get_name(path) self.assertTrue("Elder Sibling's Husband" in result) self.assertTrue("Younger Sibling's Husband" in result) self.assertTrue("Elder Sibling's Wife" in result) self.assertTrue("Younger Sibling's Wife" in result)
def test_create_next_level_paths(self): path = Path() path.set_goals(self.person, self.great_grandma) path.add_node(self.mum, RAISED_BY) new_paths = path.create_next_level_paths() self.assertEqual(2, len(new_paths)) self.assertEqual(2, len(new_paths[0].steps)) self.assertEqual(2, len(new_paths[1].steps))
def test_1_relation_apart(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) mum = Node( Person.objects.create(name='mum', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, mum) path.add_node(mum, RAISED_BY) result = get_name(path) self.assertEqual('Mother', result[0])
def test_unknownlineage_grandparents_siblings_partner(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) parent = Node( Person.objects.create(name='parent', gender='O', family_id=self.family.id)) grandparent = Node( Person.objects.create(name='grandparent', gender='O', family_id=self.family.id)) great_grandparent = Node( Person.objects.create(name='great_grandparent', gender='O', family_id=self.family.id)) grandparents_sibling = Node( Person.objects.create(name='grandparent_sibling', gender='O', family_id=self.family.id)) grandparents_siblings_partner = Node( Person.objects.create(name='grandparents_siblings_partner', gender='O', family_id=self.family.id)) path = Path() path.set_goals(person, grandparents_siblings_partner) path.add_node(parent, RAISED_BY) path.add_node(grandparent, RAISED_BY) path.add_node(great_grandparent, RAISED_BY) path.add_node(grandparents_sibling, RAISED) path.add_node(grandparents_siblings_partner, PARTNERED) result = get_name(path) self.assertEqual(10, len(result)) self.assertTrue( "Paternal Grandfather's Younger Brother's Wife" in result) self.assertTrue( "Paternal Grandfather's Elder Brother's Wife" in result) self.assertTrue("Maternal Grandmother's Sister's Husband" in result)
def test_paternal_grandfathers_younger_brothers_wife(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) dad = Node( Person.objects.create(name='dad', gender='M', family_id=self.family.id)) grandfather = Node( Person.objects.create(name='grandfather', gender='M', family_id=self.family.id, birth_year=1950)) great_grandmother = Node( Person.objects.create(name='great_grandmother', gender='F', family_id=self.family.id)) great_uncle = Node( Person.objects.create(name='great_uncle', gender='M', family_id=self.family.id, birth_year=1951)) great_aunt = Node( Person.objects.create(name='great_aunt', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, great_aunt) path.add_node(dad, RAISED_BY) path.add_node(grandfather, RAISED_BY) path.add_node(great_grandmother, RAISED_BY) path.add_node(great_uncle, RAISED) path.add_node(great_aunt, PARTNERED) result = get_name(path) self.assertEqual(1, len(result)) self.assertEqual("Paternal Grandfather's Younger Brother's Wife", result[0])
def test_add_nodes_and_duplicate(self): path = Path() path.set_goals(self.person, self.grandma) path.add_node(self.mum, RAISED_BY) self.assertEqual(1, len(path.steps)) self.assertEqual(2, len(path.nodes)) path.add_node(self.grandma, RAISED_BY) self.assertEqual(2, len(path.steps)) self.assertEqual(3, len(path.nodes)) self.assertTrue(path.success) duplicate = path.duplicate() path.add_node(self.grandpa, PARTNERED) self.assertEqual(2, len(duplicate.steps)) self.assertEqual(3, len(duplicate.nodes)) self.assertTrue(duplicate.success)
def test_father_in_law_wifes_side(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) wife = Node( Person.objects.create(name='wife', gender='F', family_id=self.family.id)) father_in_law = Node( Person.objects.create(name='father_in_law', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, father_in_law) path.add_node(wife, PARTNERED) path.add_node(father_in_law, RAISED_BY) result = get_name(path) self.assertEqual("Wife's Father", result[0])
def test_stepson(self): person = Node( Person.objects.create(name='patient zero', gender='F', family_id=self.family.id)) partner = Node( Person.objects.create(name='partner', gender='F', family_id=self.family.id)) stepson = Node( Person.objects.create(name='stepson', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, stepson) path.add_node(partner, PARTNERED) path.add_node(stepson, RAISED) result = get_name(path) self.assertTrue("Stepson" in result)
def test_daughter_in_law(self): person = Node( Person.objects.create(name='patient zero', gender='F', family_id=self.family.id)) son = Node( Person.objects.create(name='son', gender='M', family_id=self.family.id)) daughter_in_law = Node( Person.objects.create(name='daughter in law', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, daughter_in_law) path.add_node(son, RAISED) path.add_node(daughter_in_law, PARTNERED) result = get_name(path) self.assertTrue("Daughter In Law" in result)
def test_grandson_daughters_side(self): person = Node( Person.objects.create(name='patient zero', gender='F', family_id=self.family.id)) daughter = Node( Person.objects.create(name='daughter', gender='F', family_id=self.family.id)) grandson = Node( Person.objects.create(name='grandson', gender='M', family_id=self.family.id)) path = Path() path.set_goals(person, grandson) path.add_node(daughter, RAISED) path.add_node(grandson, RAISED) result = get_name(path) self.assertTrue("Grandson Daughter's Side" in result)
def test_stepmother(self): person = Node( Person.objects.create(name='patient zero', gender='M', family_id=self.family.id)) dad = Node( Person.objects.create(name='dad', gender='M', family_id=self.family.id)) stepmother = Node( Person.objects.create(name='stepmother', gender='F', family_id=self.family.id)) path = Path() path.set_goals(person, stepmother) path.add_node(dad, RAISED_BY) path.add_node(stepmother, PARTNERED) result = get_name(path) self.assertEqual('Stepmother', result[0])