def US11():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    error = []
    for fam in listFam:
        if fam.husbandId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            if fam.married != 'NA':
                husb.marriageList.append(fam.married)
            if fam.divorced != 'NA':
                husb.divorceList.append(fam.divorced)
        if fam.wifeId != 'NA':
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            if fam.married != 'NA':
                wife.marriageList.append(fam.married)
            if fam.divorced != 'NA':
                wife.divorceList.append(fam.divorced)

    for person in listPeople:
        if len(person.marriageList) == 0 and len(person.divorceList) == 0:
            continue
        else:
            if len(person.marriageList) > 1 and len(person.divorceList) == 0:
                error.append(person)
            elif len(person.marriageList) > 1:
                marr = person.marriageList
                div = person.divorceList
                marr.sort()
                div.sort()
                for i in range(1, len(marr)):
                    for j in range(0, len(div)):
                        if marr[i] < div[j]:
                            error.append(person)
                            break
    return error
def US09():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    childerror = []

    for fam in listFam:
        if len(fam.children) > 0:
            if fam.husbandId != 'NA':
                husb = main_parser.findPerson(fam.husbandId, listPeople)
                for child in fam.children:
                    c = main_parser.findPerson(child, listPeople)
                    if husb.death != 'NA':
                        newYear = (husb.death.month + 9) // 12
                        newMonth = (husb.death.month + 9) % 12
                        if newMonth == 0:
                            newMonth = 12
                        limit = datetime.date(husb.death.year + newYear,
                                              newMonth, husb.death.day)
                        if c.birthday > limit:
                            childerror.append(c)
            if fam.wifeId != 'NA':
                wife = main_parser.findPerson(fam.wifeId, listPeople)
                for child in fam.children:
                    c = main_parser.findPerson(child, listPeople)
                    if wife.death != 'NA':
                        if c.birthday > wife.death:
                            childerror.append(c)
    return childerror
def US08():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    t = datetime.datetime.today()
    today = datetime.date(t.year, t.month, t.day)

    marriageError = []
    divorceError = []

    for fam in listFam:
        if len(fam.children) > 0:
            if fam.divorced != "NA":
                newYear = (fam.divorced.month + 9) // 12
                newMonth = (fam.divorced.month + 9) % 12
                if newMonth == 0:
                    newMonth = 12
                limit = datetime.date(fam.divorced.year + newYear, newMonth,
                                      fam.divorced.day)
                for child in fam.children:
                    c = main_parser.findPerson(child, listPeople)
                    if c.birthday > limit:
                        divorceError.append([c, fam.divorced, fam.id])
            elif fam.married != "NA":
                for child in fam.children:
                    c = main_parser.findPerson(child, listPeople)
                    if c.birthday < fam.married:
                        marriageError.append([c, fam.married, fam.id])

    return marriageError, divorceError
def US03():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    peopleErrors = []
    for person in listPeople:
        if person.alive == False and person.birthday > person.death:
            peopleErrors.append(person)

    return peopleErrors
def US04():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    peopleErrors = []
    for fam in listFam:
        if fam.husbandId != 'NA':
            if fam.married != 'NA' and fam.divorced != 'NA' and fam.divorced < fam.married:
                peopleErrors.append(fam)
    return peopleErrors
def US23():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    birthdayError = []
    dictionary = {}
    for person in listPeople:
        if person.name in dictionary and person.birthday == dictionary[
                person.name][0] and person.id != dictionary[person.name][1]:
            birthdayError.append((person.birthday, person.name))
        else:
            dictionary[person.name] = (person.birthday, person.id)

    return birthdayError
def US06():  #us06: Divorce before death
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    peopleErrors = []
    for fam in listFam:
        if fam.husbandId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            if fam.divorced != 'NA' and husb.alive == False and husb.death < fam.divorced:
                husb.divorce = fam.divorced
                peopleErrors.append(husb)
        if fam.wifeId != 'NA':
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            if fam.divorced != 'NA' and wife.alive == False and wife.death < fam.divorced:
                wife.divorce = fam.divorced
                peopleErrors.append(wife)
    return peopleErrors
def US02():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    peopleErrors = []

    for fam in listFam:
        if fam.husbandId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            if fam.married != 'NA' and husb.birthday > fam.married:
                husb.marriage = fam.married
                peopleErrors.append(husb)
        if fam.wifeId != 'NA':
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            if fam.married != 'NA' and wife.birthday > fam.married:
                wife.marriage = fam.married
                peopleErrors.append(wife)
    return peopleErrors
def US20():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    individualError = []
    for fam in listFam:
        if fam.husbandId != 'NA' and fam.wifeId != 'NA':
            hParents = main_parser.findParents(fam.husbandId, listFam)
            wParents = main_parser.findParents(fam.wifeId, listFam)
            if hParents and wParents:
                hSiblings = main_parser.checkIfSiblings(hParents, fam, listFam)
                wSiblings = main_parser.checkIfSiblings(wParents, fam, listFam)
                if hSiblings == True:
                    individualError.append(fam)
                elif wSiblings == True:
                    individualError.append(fam)
    return individualError
def US05():  # US05: Marriage Before Death
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    peopleErrors = []
    for fam in listFam:
        if fam.husbandId != 'NA':
            h = main_parser.findPerson(fam.husbandId, listPeople)
            husb = h.createDeepCopy(h)
            if fam.married != 'NA' and husb.alive == False and husb.death < fam.married:
                husb.marriage = fam.married
                peopleErrors.append(husb)
        if fam.wifeId != 'NA':
            w = main_parser.findPerson(fam.wifeId, listPeople)
            wife = w.createDeepCopy(w)
            if fam.married != 'NA' and wife.alive == False and wife.death < fam.married:
                wife.marriage = fam.married
                peopleErrors.append(wife)
    return peopleErrors
def US07():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    t = datetime.datetime.today()
    today = datetime.date(t.year, t.month, t.day)

    deathError = []
    peopleError = []

    for person in listPeople:
        if person.alive == False:
            limit = person.birthday.year + 150
            if person.death.year > limit:
                deathError.append(person)
        if today.year > person.birthday.year + 150 and person.alive == True:
            peopleError.append(person)

    return deathError, peopleError
def US19():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    individualError = []

    #check if parents of husband and spouse. If parents are siblings in each others families then first cousins. Return
    for fam in listFam:
        if fam.husbandId != 'NA' and fam.wifeId != 'NA':
            hParents = main_parser.findParents(fam.husbandId, listFam)
            wParents = main_parser.findParents(fam.wifeId, listFam)
            if hParents and wParents:
                #check if either hParents are siblings with wParents
                siblings = main_parser.checkIfSiblings(hParents, wParents,
                                                       listFam)
                if siblings == True:
                    individualError.append(fam)
    return individualError
def US10():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    marriageerror = []

    for fam in listFam:
        if fam.husbandId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            limit = husb.birthday.year + 14
            if fam.married != 'NA' and fam.married.year < limit:
                marriageerror.append(husb)
        if fam.wifeId != 'NA':
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            limit = wife.birthday.year + 14
            if fam.married != 'NA' and fam.married.year < limit:
                marriageerror.append(wife)
    return marriageerror
def US01():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    t = datetime.datetime.today()
    today = datetime.date(t.year, t.month, t.day)
    peopleErrors = []
    famErrors = []
    for person in listPeople:
        if person.birthday > today:
            peopleErrors.append(person)
        elif person.death != 'NA' and person.death > today:
            peopleErrors.append(person)

    for fam in listFam:
        if fam.married != 'NA' and fam.married > today:
            famErrors.append(fam)
        elif fam.divorced != 'NA' and fam.divorced > today:
            famErrors.append(fam)

    return peopleErrors, famErrors
def US24():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    familyError = []
    dictionary = {}
    for fam in listFam:
        if fam.husbandId != 'NA' and fam.wifeId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            if husb.name in dictionary and dictionary[
                    husb.name][1] == fam.married:
                familyError.append((husb.name, fam.married))
            else:
                dictionary[husb.name] = (wife.name, fam.married)
            if wife.name in dictionary and dictionary[
                    wife.name][1] == fam.married:
                familyError.append((wife.name, fam.married))
            else:
                dictionary[wife.name] = (husb.name, fam.married)
    return familyError
def US12():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)
    error = []
    for fam in listFam:
        if len(fam.children) > 0:
            if fam.husbandId != 'NA':
                husb = main_parser.findPerson(fam.husbandId, listPeople)
            for child in fam.children:
                c = main_parser.findPerson(child, listPeople)
                limit = husb.birthday.year + 80
                if c.birthday.year > limit:
                    error.append([c, husb])
            if fam.wifeId != 'NA':
                wife = main_parser.findPerson(fam.wifeId, listPeople)
            for child in fam.children:
                c = main_parser.findPerson(child, listPeople)
                limit = wife.birthday.year + 60
                if c.birthday.year > limit:
                    error.append([c, wife])
    return error
def US21():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    Error = []

    flag1 = False
    flag2 = False
    for fam in listFam:
        if fam.husbandId != 'NA':
            husb = main_parser.findPerson(fam.husbandId, listPeople)
            if husb.gender != 'M':
                flag1 = True
        if fam.wifeId != 'NA':
            wife = main_parser.findPerson(fam.wifeId, listPeople)
            if wife.gender != 'F':
                flag2 = True
        if flag1 or flag2:
            Error.append(fam)
            flag1 = False
            flag2 = False
    return Error
def US22():
    file_ = 'gedcomTests/main_test.ged'
    listPeople, listFam = main_parser.parse(file_)

    IndividualIdError = []
    FamilyIDError = []

    dictionary = {}
    for person in listPeople:
        if person.id in dictionary and dictionary[person.id] != person:
            IndividualIdError.append(person.id)
        else:
            dictionary[person.id] = person

    dictionary = {}
    for family in listFam:
        if family.id in dictionary and dictionary[family.id] != family:
            FamilyIDError.append(family.id)
        else:
            dictionary[family.id] = family

    return IndividualIdError, FamilyIDError