def test_US18_Siblings_should_not_marry(self): t1 = Family("t1") t2 = Family("t2") t3 = Family("t3") t4 = Family("t4") t5 = Family("t5") t6 = Family("t6") p1 = Individual("p1") p2 = Individual("p2") p3 = Individual("p3") p4 = Individual("p4") # -------------------------------------------------- t1.set_husband(p1) t1.set_wife(p2) t4.set_husband(p3) t4.set_wife(p4) ''' t2.add_child(p1) t3.add_child(p2) t4.set_husband(p3) t4.set_wife(p4) t5.add_child(p3) t5.add_child(p4) ''' # -------------------------------------------------- p1.set_parentFamily(t2) p2.set_parentFamily(t3) p3.set_parentFamily(t5) p4.set_parentFamily(t5) # -------------------------------------------------- assert t1.siblings_should_not_marry() == True #assert t2.siblings_should_not_marry() == True assert t4.siblings_should_not_marry() == False
def test_date_compare(self): fam_1 = Family("01") ind_1 = Individual("01") ind_1.set_birthDate((2019, 9, 1)) ind_1.set_parentFamily(fam_1) fam_1.set_marriedDate((2019, 9, 2)) ind_1.set_deathDate((2020, 9, 1)) fam_2 = Family("02") ind_2 = Individual("02") ind_2.set_birthDate((2019, 8, 1)) ind_2.set_parentFamily((fam_2)) fam_2.set_marriedDate((2019, 7, 1)) ind_2.set_deathDate((2018, 8, 1)) assert ind_1.birth_before_marriage() == True assert ind_2.birth_before_marriage() == False assert ind_1.birth_before_death() == True assert ind_2.birth_before_death() == False
def test_US20_Aunts_and_uncles(self): t1 = Family("t1") t2 = Family("t2") t3 = Family("t3") t4 = Family("t4") t5 = Family("t5") t6 = Family("t6") t7 = Family("t7") t8 = Family("t8") t9 = Family("t9") t10 = Family("t10") t11 = Family("t11") t12 = Family("t12") p1 = Individual("p1") p2 = Individual("p2") p3 = Individual("p3") p4 = Individual("p4") p5 = Individual("p5") p6 = Individual("p6") p7 = Individual("p7") p8 = Individual("p8") p9 = Individual("p9") p10 = Individual("p10") p11 = Individual("p11") # -------------------------------------------------- p11.set_parentFamily(t1) t1.set_husband(p1) t1.set_wife(p2) p1.set_parentFamily(t2) p2.set_parentFamily(t3) #t2.set_husband(p3) #t2.set_wife(p4) #t3.set_husband(p5) #t3.set_wife(p6) t2.set_children([p1, p7, p8]) t3.set_children([p2, p9, p10]) ''' t1.add_child(p3) t1.add_child(p4) t2.set_husband(p3) t3.set_wife(p4) t2.add_child(p5) t3.add_child(p6) t4.set_husband(p7) t4.set_wife(p8) t4.add_child(p9) t4.add_child(p10) t5.set_husband(p9) t5.add_child(p11) t6.set_husband(p10) t6.set_wife(p11) ''' # -------------------------------------------------- assert p11.aunts_and_uncles() == True
def test_US19_First_cousins_should_not_marry(self): t1 = Family("t1") t2 = Family("t2") t3 = Family("t3") t4 = Family("t4") t5 = Family("t5") t6 = Family("t6") t7 = Family("t7") t8 = Family("t8") t9 = Family("t9") p1 = Individual("p1") p2 = Individual("p2") p3 = Individual("p3") p4 = Individual("p4") p5 = Individual("p5") p6 = Individual("p6") p7 = Individual("p7") p8 = Individual("p8") # -------------------------------------------------- ''' t1.add_child(p1) t1.add_child(p2) t2.set_wife(p1) t2.add_child(p3) t3.set_wife(p2) t3.add_child(p4) t4.set_husband(p3) t5.set_wife(p4) t6.add_child(p5) t6.add_child(p6) t7.set_wife(p5) t8.set_wife(p6) t7.add_child(p7) t8.add_child(p8) t9.set_wife(p7) t9.set_husband(p8) ''' # -------------------------------------------------- p3.set_parentFamily(t1) t1.set_husband(p8) t1.set_wife(p7) p8.set_parentFamily(t2) p7.set_parentFamily(t3) t2.add_child(p8) t3.add_child(p7) assert p3.first_cousins_should_not_marry() == True
def parse(self): #from Individual import Individual #from Family import Family offset = 0 for i in range(len(self._data[1]) - 1): # enumerate individuals start_index = self._data[1][i] end_index = self._data[1][i + 1] # print(self._data[0][start_index:end_index]) # TODO: check deplicated ids id = self._data[0][start_index][2] if id in self._individuals: offset += 1 id = "@I" + str(int(id[2:-1]) + offset) + "@" new_indi = Individual(id) new_indi.set_lineNum(self._data[3][start_index]) self._individuals[id] = new_indi # print(start_index, end_index) for j in range(start_index + 1, end_index): level, tag, arguments = self._data[0][j] if tag == "NAME": new_indi.set_name("".join(arguments)) elif tag == "SEX": new_indi.set_gender(arguments[0]) elif tag == "BIRT": # set missing dates to Jan/01 j += 1 level, tag, arguments = self._data[0][j] try: new_indi.set_birthDate(arguments) except ValueError as e: print(e) # TODO:how to handle error? elif tag == "DEAT": j += 1 level, tag, arguments = self._data[0][j] new_indi.set_deathDate(arguments) elif tag == "FAMS": if arguments[0] not in self._families: new_fam = Family(arguments[0]) self._families[arguments[0]] = new_fam new_indi.add_to_family(self._families[arguments[0]]) elif tag == "FAMC": if arguments[0] not in self._families: new_fam = Family(arguments[0]) self._families[arguments[0]] = new_fam new_indi.set_parentFamily(self._families[arguments[0]]) offset = 0 for i in range(len(self._data[2]) - 1): start_index = self._data[2][i] end_index = self._data[2][i + 1] # print(self._data[0][start_index:end_index]) id = self._data[0][start_index][2] # if id in self._families: #TODO: handle duplicate # offset+=1 # id = "@F" + str(int(id[2:-1]) + offset) + "@" new_fam = Family(id) new_fam.set_lineNum(self._data[3][start_index]) self._families[id] = new_fam for j in range(start_index + 1, end_index): level, tag, arguments = self._data[0][j] # print(level, tag, arguments) if tag == "HUSB": new_fam.set_husband(self._individuals[arguments[0]]) elif tag == "WIFE": new_fam.set_wife(self._individuals[arguments[0]]) elif tag == "CHIL": new_fam.add_child(self._individuals[arguments[0]]) elif tag == "MARR": j += 1 level, tag, arguments = self._data[0][j] # print(level, tag, arguments) try: new_fam.set_marriedDate(arguments) except: continue elif tag == "DIV": j += 1 level, tag, arguments = self._data[0][j] # print(level, tag, arguments) try: new_fam.set_divorcedDate(arguments) except: continue