Permalink
Browse files

Step 4 - Isolate the average age algorithm

  • Loading branch information...
lgiordani committed Jul 15, 2017
1 parent d619017 commit 9db18036eee2f6712384195fcd970303387291f6
Showing with 11 additions and 1 deletion.
  1. +4 −1 datastats/datastats.py
  2. +7 −0 tests/test_datastats.py
View
@@ -4,6 +4,9 @@
class DataStats:
def _avg_age(self, data):
return math.floor(sum([e['age'] for e in data])/len(data))
def _stats(self, data, iage, isalary):
# iage and isalary are the starting age and salary used to
# compute the average yearly increase of salary.
@@ -29,7 +32,7 @@ def _stats(self, data, iage, isalary):
'£{}'.format(str(min(salaries)))]
return {
'avg_age': math.floor(sum([e['age'] for e in data])/len(data)),
'avg_age': self._avg_age(data),
'avg_salary': math.floor(sum(
[int(e['salary'][1:]) for e in data])/len(data)),
'avg_yearly_increase': yearly_avg_increase,
View
@@ -78,3 +78,10 @@ def test__stats():
"salary": "£27888"
}]
}
def test__avg_age():
ds = DataStats()
assert ds._avg_age(test_data) == 62

0 comments on commit 9db1803

Please sign in to comment.