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_US12_parents_not_too_old(self): t1 = Family("t1") t2 = Family("t2") p1 = Individual("p1") p2 = Individual("p2") p3 = Individual("p3") p4 = Individual("p4") p5 = Individual("p5") p6 = Individual("p6") t1.set_wife(p1) t1.set_husband(p2) t1.add_child(p3) t2.set_wife(p4) t2.set_husband(p5) t2.add_child(p6) p1.set_birthDate(["1", "JAN", "1990"]) p2.set_birthDate(["1", "JAN", "1990"]) p4.set_birthDate(["1", "JAN", "1790"]) p5.set_birthDate(["1", "JAN", "1790"]) p3.set_birthDate(["1", "JAN", "2010"]) p6.set_birthDate(["1", "JAN", "2000"]) # --------------------------------- assert t1.parents_not_too_old() == True assert t2.parents_not_too_old() == False
def test1(self): male1 = Individual("P01") female1 = Individual("P02") family1 = Family("F01") male1.set_deathDate(["5", "MAR", "2000"]) female1.set_deathDate(["9", "APR", "2002"]) family1.set_husband(male1) family1.set_wife(female1) family1.set_divorced(["1", "JAN", "1999"]) self.assertTrue(family1.divorce_before_death())
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 test3(self): male1 = Individual("P01") female1 = Individual("P02") child1 = Individual("P03") family1 = Family("F01") family1.add_child(child1) male1.set_deathDate(["5", "MAR", "2000"]) female1.set_deathDate(["9", "APR", "2002"]) child1.set_birthDate(["6", "MAR", "2000"]) family1.set_husband(male1) family1.set_wife(female1) self.assertTrue(family1.birth_before_death_of_parents())
def test_US10_marriage_after_14(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") male1.set_birthDate(['8', 'SEP', '2000']) female1.set_birthDate(['8', 'SEP', '2000']) t1.set_husband(male1) t1.set_wife(female1) t1.set_marriedDate(['8', 'SEP', '2014']) # -------------------------------------------------- t2 = Family("F02") male2 = Individual("P03") female2 = Individual("P04") male2.set_birthDate(['7', 'SEP', '2000']) female2.set_birthDate(['8', 'SEP', '2000']) t2.set_husband(male2) t2.set_wife(female2) t2.set_marriedDate(['8', 'SEP', '2014']) # -------------------------------------------------- t3 = Family("F03") male3 = Individual("P05") female3 = Individual("P06") male3.set_birthDate(['8', 'SEP', '2000']) female3.set_birthDate(['7', 'SEP', '2000']) t3.set_husband(male3) t3.set_wife(female3) t3.set_marriedDate(['8', 'SEP', '2014']) # -------------------------------------------------- t4 = Family("F04") male4 = Individual("P07") female4 = Individual("P08") male4.set_birthDate(['1', 'SEP', '1990']) female4.set_birthDate(['2', 'SEP', '1990']) t4.set_husband(male4) t4.set_wife(female4) t4.set_marriedDate(['8', 'SEP', '2014']) # -------------------------------------------------- t5 = Family("F05") male5 = Individual("P09") female5 = Individual("P10") male5.set_birthDate(['09', 'APR', '1997']) female5.set_birthDate(['19', 'DEC', '1997']) t5.set_husband(male5) t5.set_wife(female5) t5.set_marriedDate(['1', 'JUN', '2007']) # -------------------------------------------------- assert t1.marriage_after_14() == False assert t2.marriage_after_14() == False assert t3.marriage_after_14() == False assert t4.marriage_after_14() == True assert t5.marriage_after_14() == False
def test_US05_marriage_before_death(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") male1.set_deathDate(['8', 'SEP', '2010']) female1.set_deathDate(['8', 'SEP', '2011']) t1.set_husband(male1) t1.set_wife(female1) t1.set_marriedDate(['8', 'SEP', '2000']) # --------------------------------- t2 = Family("F02") male2 = Individual("P03") female2 = Individual("P04") male2.set_deathDate(['8', 'SEP', '1999']) female2.set_deathDate(['9', 'SEP', '2011']) t2.set_husband(male2) t2.set_wife(female2) t2.set_marriedDate(['8', 'SEP', '2000']) # --------------------------------- t3 = Family("F03") male3 = Individual("P05") female3 = Individual("P06") male3.set_deathDate(['8', 'SEP', '2003']) female3.set_deathDate(['9', 'SEP', '1998']) t3.set_husband(male3) t3.set_wife(female3) t3.set_marriedDate(['8', 'SEP', '2000']) # --------------------------------- t4 = Family("F04") male4 = Individual("P07") female4 = Individual("P08") male4.set_deathDate(['8', 'SEP', '1998']) female4.set_deathDate(['9', 'SEP', '1999']) t4.set_husband(male4) t4.set_wife(female4) t4.set_marriedDate(['8', 'SEP', '2000']) # --------------------------------- t5 = Family("F05") male5 = Individual("P09") female5 = Individual("P10") male5.set_deathDate(['8', 'SEP', '2009']) female5.set_deathDate(['8', 'SEP', '2009']) t5.set_husband(male5) t5.set_wife(female5) t5.set_marriedDate(['8', 'SEP', '2009']) # --------------------------------- assert t1.marriage_before_death() == True assert t2.marriage_before_death() == False assert t3.marriage_before_death() == False assert t4.marriage_before_death() == False assert t5.marriage_before_death() == True
def test_US17_No_marriages_to_descendants(self): t1 = Family("t1") t2 = Family("t2") t3 = Family("t3") t4 = Family("t4") 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") t1.set_husband(p1) t1.set_wife(p2) t1.add_child(p3) t2.set_wife(p3) t2.set_husband(p4) t2.add_child(p5) t3.set_husband(p6) t3.set_wife(p7) t3.add_child(p8) t4.set_husband(p6) t4.set_wife(p8) t4.add_child(p9)
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 test_US21_Correct_Gender_For_Role(self): t1 = Family("t1") t2 = Family("t2") p1 = Individual("p1") p2 = Individual("p2") p3 = Individual("p3") p4 = Individual("p4") # --------------------------------- t1.set_wife(p1) t1.set_husband(p2) t2.set_wife(p3) t2.set_husband(p4) p1.set_gender('F') p2.set_gender('M') p4.set_gender('F') p3.set_gender('M') # --------------------------------- assert t1.correct_gender_for_role() == True assert t2.correct_gender_for_role() == False
def test_US08_birth_before_marriage_of_parents(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") child1 = Individual("P03") t1.add_child(child1) t1.set_marriedDate(['8', 'SEP', '2000']) child1.set_birthDate(["6", "JAN", "1998"]) t1.set_husband(male1) t1.set_wife(female1) # --------------------------------- t2 = Family("F02") male2 = Individual("P04") female2 = Individual("P05") child2 = Individual("P06") t2.add_child(child2) t2.set_marriedDate(['8', 'SEP', '2000']) child2.set_birthDate(["6", "JAN", "2001"]) t2.set_husband(male2) t2.set_wife(female2) # --------------------------------- t3 = Family("F03") male3 = Individual("P07") female3 = Individual("P08") child3 = Individual("P09") t3.add_child(child3) t3.set_marriedDate(['6', 'MAR', '2000']) child3.set_birthDate(["6", "MAR", "2000"]) t3.set_husband(male3) t3.set_wife(female3) # --------------------------------- assert t1.birth_before_marriage_of_parents() == False assert t2.birth_before_marriage_of_parents() == True assert t3.birth_before_marriage_of_parents() == False
def test_US06_divorse_before_death(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") male1.set_deathDate(["5", "MAR", "2000"]) female1.set_deathDate(["9", "APR", "2002"]) t1.set_husband(male1) t1.set_wife(female1) t1.set_divorcedDate(["1", "JAN", "1999"]) # --------------------------------- t2 = Family("F02") male2 = Individual("P03") female2 = Individual("P04") male2.set_deathDate(["5", "MAR", "2000"]) female2.set_deathDate(["9", "APR", "2002"]) t2.set_husband(male2) t2.set_wife(female2) t2.set_divorcedDate(["1", "JAN", "2003"]) # --------------------------------- assert t1.divorce_before_death() == True assert t2.divorce_before_death() == False
def test_US04_marriage_before_divorce(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") male1.set_deathDate(['8', 'SEP', '2010']) female1.set_deathDate(['8', 'SEP', '2011']) t1.set_husband(male1) t1.set_wife(female1) t1.set_marriedDate(['8', 'SEP', '2000']) t1.set_divorcedDate(['8', 'SEP', '2009']) # --------------------------------- t2 = Family("F02") male2 = Individual("P03") female2 = Individual("P04") male2.set_deathDate(['8', 'SEP', '2012']) female2.set_deathDate(['8', 'SEP', '2013']) t2.set_husband(male2) t2.set_wife(female2) t2.set_marriedDate(['8', 'SEP', '2005']) t2.set_divorcedDate(['8', 'SEP', '2004']) # --------------------------------- assert t1.marriage_before_divorce() == True assert t2.marriage_before_divorce() == False
def test_US09_birth_before_death_of_parent(self): t1 = Family("F01") male1 = Individual("P01") female1 = Individual("P02") child1 = Individual("P03") t1.add_child(child1) male1.set_deathDate(["5", "MAR", "2000"]) female1.set_deathDate(["9", "APR", "2002"]) child1.set_birthDate(["6", "JAN", "1998"]) t1.set_husband(male1) t1.set_wife(female1) # --------------------------------- t2 = Family("F02") male2 = Individual("P04") female2 = Individual("P05") child2 = Individual("P06") t2.add_child(child2) male2.set_deathDate(["5", "MAR", "2000"]) female2.set_deathDate(["9", "APR", "2002"]) child2.set_birthDate(["6", "JAN", "2001"]) t2.set_husband(male2) t2.set_wife(female2) # --------------------------------- t3 = Family("F03") male3 = Individual("P07") female3 = Individual("P08") child3 = Individual("P09") t3.add_child(child3) male3.set_deathDate(["5", "MAR", "2000"]) female3.set_deathDate(["9", "APR", "2002"]) child3.set_birthDate(["6", "MAR", "2000"]) t3.set_husband(male3) t3.set_wife(female3) # --------------------------------- assert t1.birth_before_death_of_parents() == True assert t2.birth_before_death_of_parents() == False assert t3.birth_before_death_of_parents() == True
def testNoMarriagesToDescendants(self): ## BASE CASE(husband and wife has no parent family) #fam1 fam1 = Family("1") # Husband ind1 = Individual("1") ind1.set_gender("M") ind1.add_to_family(fam1) # Wife ind2 = Individual("2") ind2.set_gender("F") ind2.add_to_family(fam1) # Child 1 ind3 = Individual("3") ind3.set_gender("M") # Child 2 ind4 = Individual("4") ind4.set_gender("M") # Child 3 ind5 = Individual("5") ind5.set_gender("F") fam1.set_husband(ind1) fam1.set_wife(ind2) fam1.set_marriedDate((1989, 7, 25)) fam1.set_children([ind3, ind4, ind5]) self.assertTrue(ind1.no_marriages_to_descendants()) #fam2 fam2 = Family("2") # Husband ind6 = Individual("6") ind6.set_gender("M") ind6.add_to_family(fam2) # Wife ind7 = Individual("7") ind7.set_gender("F") ind7.add_to_family(fam2) # Child 1 ind8 = Individual("8") # Child 2 ind9 = Individual("9") ind9.set_gender("M") # Child 3 ind10 = Individual("10") ind10.set_gender("F") fam2.set_husband(ind6) fam2.set_wife(ind7) fam2.set_marriedDate((1989, 7, 25)) fam2.set_children([ind6, ind9, ind10]) self.assertFalse(ind7.no_marriages_to_descendants()) #fam3 fam3 = Family("3") # Husband fam3.set_husband(ind3) ind3.add_to_family(fam3) # Wife ind11 = Individual("11") ind11.set_gender("F") # Child 1 ind12 = Individual("12") ind12.set_gender("M") # Child 2 ind13 = Individual("13") ind13.set_gender("F") fam3.set_wife(ind11) fam3.set_children([ind12, ind13]) self.assertTrue(ind1.no_marriages_to_descendants()) #fam4 fam4 = Family("4") # Husband fam4.set_husband(ind12) ind12.add_to_family(fam4) # Wife ind14 = Individual("14") ind14.set_gender("F") # Child 1 ind15 = Individual("15") # Child 2 ind16 = Individual("16") ind16.set_gender("M") fam4.set_wife(ind14) fam4.set_children([ind2, ind16]) self.assertFalse(ind1.no_marriages_to_descendants())
def marriage_before_divorce(Family): from datetime import date marriage = Family.get_marriedDate() divorce = Family.get_divorcedDate() timediff = date(*marriage) - date(*divorce) if timediff.days < 0: return True print("Error marriage before divorce: Marriage date of " + Family.get_id + " happened after the divorce date.") return False if __name__ == '__main__': # ----------------------------------------------- fam1 = Family("F01") fam1.set_divorcedDate(['8', 'SEP', '2009']) fam1.set_marriedDate(['8', 'SEP', '2000']) fam2 = Family("F02") male1 = Individual("P01") per1 = Individual("P01") per2 = Individual("P02") per1.set_deathDate(['8', 'SEP', '2010']) per2.set_deathDate(['8', 'SEP', '2011']) fam2.set_husband(per1) fam2.set_wife(per2) fam2.set_marriedDate(['8', 'SEP', '2001']) #------------------------------------------------- print('Running unit tests') unittest.main()
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
def testMLastNames(self): #family1 fam1 = Family("1") #Husband ind1 = Individual("1") ind1.set_gender("M") ind1.set_name("Charles Glass") #Wife ind2 = Individual("2") ind2.set_gender("F") ind2.set_name("Betty Glass") #Child 1 ind3 = Individual("3") ind3.set_gender("M") ind3.set_name("Nate Glass") # Child 2 ind4 = Individual("4") ind4.set_gender("M") ind4.set_name("Bobby Glass") # Child 3 ind5 = Individual("5") ind5.set_gender("M") ind5.set_name("Jack Glass") fam1.set_wife(ind2) fam1.set_husband(ind1) fam1.set_marriedDate((1989, 7, 25)) fam1.set_children([ind3, ind4, ind5]) self.assertTrue(fam1.male_last_names()) #family2 fam2 = Family("2") # Husband ind6 = Individual("6") ind6.set_gender("M") ind6.set_name("Charles Glass") # Wife ind7 = Individual("7") ind7.set_gender("F") ind7.set_name("Betty Glass") # Child 1 ind8 = Individual("8") ind8.set_gender("F") ind8.set_name("Nancy Glass") # Child 2 ind9 = Individual("9") ind9.set_gender("M") ind9.set_name("Bobby Tarantino") # Child 3 ind10 = Individual("10") ind10.set_gender("M") ind10.set_name("Jack Glass") fam2.set_wife(ind7) fam2.set_husband(ind6) fam2.set_marriedDate((1992, 3, 17)) fam2.set_children([ind8, ind9, ind10]) self.assertFalse(fam2.male_last_names()) #fam3 fam3 = Family('3') #husband fam3.set_husband(ind3) ind3.add_to_family(fam3) #wife ind11 = Individual("11") ind11.set_gender("F") ind11.set_name("Sandy Glass") # Child 1 ind12 = Individual("12") ind12.set_gender("F") ind12.set_name("Nancy T") # Child 2 ind13 = Individual("13") ind13.set_gender("M") ind13.set_name("Bobby Glass") fam3.set_wife(ind11) fam3.set_children([ind12, ind13]) self.assertTrue(fam1.male_last_names()) # fam4 fam4 = Family('4') # husband fam4.set_husband(ind4) ind4.add_to_family(fam4) # wife ind14 = Individual("14") ind14.set_gender("F") ind14.set_name("Sandy Glass") # Child 1 ind15 = Individual("15") ind15.set_gender("F") ind15.set_name("Nancy T") # Child 2 ind16 = Individual("16") ind16.set_gender("M") ind16.set_name("Bobby T") fam4.set_wife(ind14) fam4.set_children([ind15, ind16]) self.assertFalse(fam1.male_last_names())