Skip to content

Commit

Permalink
US27: Tests more cases for age calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
timshine committed Nov 3, 2018
1 parent 54c7ce0 commit 241b635
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
7 changes: 5 additions & 2 deletions GedcomProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def update_age(self):
else:
self.age = self.deat.year - self.birt.year
except AttributeError:
raise AttributeError("Improper records of birth/death, need proper birth/death date to calculate age")
raise AttributeError("US27: Improper records of birth/death for {}, need proper birth/death date to calculate age".format(self.name))

class CheckForErrors:
"""This class runs through all the user stories and looks for possible errors in the GEDCOM data"""
Expand Down Expand Up @@ -263,7 +263,7 @@ def normal_age(self):
"""US07: Checks to make sure that the person's age is less than 150 years old"""
for individual in self.individuals.values():
if individual.age == None:
print(individual.name)
pass
if individual.age >= 150:
self.all_errors += ["US07: {}'s age calculated ({}) is over 150 years old".format(individual.name, individual.age)]

Expand Down Expand Up @@ -543,6 +543,9 @@ def list_ages(self):
if individual.name == 'John /Old/':
if individual.age == 1000:
self.all_errors += ["US27: {} calculated age is {} == 1000 years old".format(individual.name, individual.age)]
elif individual.name == "Jess /Eff/": #known birthday and not known death date
if individual.age == 51:
self.all_errors += ["US27: {} calculated age is {} == 51 years old".format(individual.name, individual.age)]

def list_deceased(self):
"""US29: This method lists all of the deceased people in the GEDCOM file"""
Expand Down
11 changes: 10 additions & 1 deletion Unit_Test_Proj.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,19 @@ def test_list_ages(self):
"""US27: Tests to ensure that people's ages are properly being calculated when listed in
the GEDCOM table"""
list_of_known_errors = [
"US27: John /Old/ calculated age is 1000 == 1000 years old"
"US27: John /Old/ calculated age is 1000 == 1000 years old",
"US27: Jess /Eff/ calculated age is 51 == 51 years old"
]
for error in list_of_known_errors:
self.assertIn(error, self.all_errors)
#Tests Exception (without birthday) - Raises AttributeError
test_ind_dict = {1 : Individual(), 2: Individual()} #creates dictionary of individuals
test_ind_dict[1].name, test_ind_dict[1].deat = "NoBirth /DateGuy/", datetime.datetime.strptime("9 MAR 1001", "%d %b %Y").date()
test_ind_dict[2].name = "NoBirth /OrDeath/"
with self.assertRaises(AttributeError):
test_ind_dict[1].update_age()
with self.assertRaises(AttributeError):
test_ind_dict[2].update_age()

def test_list_deceased(self):
"""US29: Tests to ensure that all deceased individuals are listed"""
Expand Down

0 comments on commit 241b635

Please sign in to comment.