Skip to content

Commit

Permalink
US13 Function and Test
Browse files Browse the repository at this point in the history
Implemented the test and the function for user story 13, checking to see if they are born between 2 days and 8 months of eachother, if so, add to error list
  • Loading branch information
kgensheimer committed Oct 15, 2018
1 parent 252eb77 commit e923ee6
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Capture.PNG
__pycache__
scrap.py
10 changes: 5 additions & 5 deletions Bad_GEDCOM_test_data.ged
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@
1 NAME Thirteen /Fif/
1 SEX M
1 BIRT
2 DATE 1 JAN 2006
2 DATE 6 JAN 2006
1 FAMC @F14@
0 @I43@ INDI
1 NAME Fourteen /Fif/
Expand Down Expand Up @@ -414,7 +414,7 @@
2 DATE 1 JAN 1961
1 FAMC @F20@
1 FAMS @F21@
0 NOTE Start of the Families
0 NOTE -----------------Start of the Families-------------------
0 @F1@ FAM
1 HUSB @I1@
1 WIFE @I2@
Expand Down Expand Up @@ -547,16 +547,16 @@
0 @F18@ FAM
1 HUSB @I57@
1 WIFE @I58@
1 MARR
1 MARR
2 DATE 15 FEB 1920
1 DIV
1 DIV
2 DATE 16 MAR 1935
1 CHIL @I59@
1 CHIL @I60@
0 @F19@ FAM
1 HUSB @I60@
1 WIFE @I61@
1 MARR
1 MARR
2 DATE 20 FEB 1940
1 CHIL @I62@
0 @F20@ FAM
Expand Down
29 changes: 26 additions & 3 deletions GedcomProject.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from prettytable import PrettyTable
import datetime
from collections import defaultdict
from copy import deepcopy
import os

class AnalyzeGEDCOM:
Expand Down Expand Up @@ -159,7 +160,7 @@ def __init__(self, ind_dict, fam_dict, print_errors):
self.spouses_too_young() #US10
self.no_bigamy() #US11
self.parents_too_old() #US12
#Call US13 Here
self.sibling_spacing() #US13
#Call US14 Here
self.too_many_siblings() #US15
self.no_marriage_to_descendants()
Expand Down Expand Up @@ -343,12 +344,34 @@ def parents_too_old(self):
if self.individuals[self.family[indi.famc].wife].age > (indi.age + 60): #check the mother
self.all_errors += ["US12: {} is over 60 years older than his child {}".format(self.individuals[self.family[indi.famc].wife].name, indi.name)]

def sibling_spacing(self):
"""US13: Makes sure that birth dates of siblings should be more than 8 months apart
or less than 2 days apart (twins may be born one day apart, e.g. 11:59 PM and 12:02 AM the following calendar day)"""
for fam in self.family.values():
childIDLstCopy = deepcopy(list(fam.chil))
childIDLstCopy.sort() #needs to be sorted since every time the program runs, the order of the children set changes

for i in range(len(childIDLstCopy)):
for j in range(i + 1, len(childIDLstCopy)):
child1 = self.individuals[childIDLstCopy[i]]
child2 = self.individuals[childIDLstCopy[j]]
daysApart = abs(child1.birt.day - child2.birt.day)
monthsApart = abs(child1.birt.month - child2.birt.month)
if daysApart > 2 and monthsApart < 8 :
self.all_errors += ["US13: Siblings {} and {}'s births are only ".format(child1.name, child2.name) + str(daysApart) + " days apart"]



def too_many_births(self):
"""US14: Makes sure that no more than five siblings should be born at the same time"""
#for fam in self.family.values():

def too_many_siblings(self):
"""US15: Tests to ensure that there are fewer than 15 siblings in a family"""
for fam in self.family.values():
if len(fam.chil)>=15:
self.all_errors+=["US15: The {} family has 15 or more siblings".format(self.individuals[fam.husb].fams)]

def descendants_help(self, initial_indi, current_indi ):
"""Recursive helper for US17"""
if(len(current_indi.fams)>0):
Expand All @@ -357,7 +380,7 @@ def descendants_help(self, initial_indi, current_indi ):
self.all_errors+=["US17: {} cannot be married to their descendant {}".format(initial_indi.name, current_indi.name)]
for child in self.family[fam].chil:
self.descendants_help(initial_indi,self.individuals[child])

def no_marriage_to_descendants(self):
"""US17: Tests to ensure that individuals and their descendants do not marry each other"""
for person in self.individuals.values(): #Traverse all individuals and do a top down search of all descendants
Expand Down
19 changes: 18 additions & 1 deletion Unit_Test_Proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,24 @@ def test_parents_too_old(self):
for error in list_of_known_errors:
self.assertIn(error, self.all_errors)

#INSERT US13 TEST HERE
def test_sibling_spacing(self):
list_of_known_errors = ["US13: Siblings One /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Two /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Three /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Four /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Five /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Six /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Seven /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Eight /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Nine /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Ten /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings El /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Twelve /Fif/ and Thirteen /Fif/'s births are only 5 days apart",
"US13: Siblings Thirteen /Fif/ and Fourteen /Fif/'s births are only 5 days apart",
"US13: Siblings Thirteen /Fif/ and Fifteen /Fif/'s births are only 5 days apart",
"US13: Siblings Allen /Leffe/ and Ava /Leffe/'s births are only 9 days apart"]
for error in list_of_known_errors:
self.assertIn(error, self.all_errors)

#INSERT US14 TEST HERE

Expand Down

0 comments on commit e923ee6

Please sign in to comment.