Skip to content

Commit

Permalink
Step 7 - Isolate max and min salary algorithms
Browse files Browse the repository at this point in the history
  • Loading branch information
lgiordani committed Jul 21, 2017
1 parent 4005145 commit 17b2413
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
14 changes: 8 additions & 6 deletions datastats/datastats.py
Expand Up @@ -22,25 +22,27 @@ def _avg_yearly_increase(self, data, iage, isalary):

return math.floor(average_salary_increase/average_age_increase)

def _stats(self, data, iage, isalary):
def _max_salary(self, data):
# Compute max salary
salaries = [int(e['salary'][1:]) for e in data]
threshold = '£' + str(max(salaries))

max_salary = [e for e in data if e['salary'] == threshold]
return [e for e in data if e['salary'] == threshold]

def _min_salary(self, data):
# Compute min salary
salaries = [int(d['salary'][1:]) for d in data]
min_salary = [e for e in data if e['salary'] ==
'£{}'.format(str(min(salaries)))]
return [e for e in data if e['salary'] ==
'£{}'.format(str(min(salaries)))]

def _stats(self, data, iage, isalary):
return {
'avg_age': self._avg_age(data),
'avg_salary': self._avg_salary(data),
'avg_yearly_increase': self._avg_yearly_increase(
data, iage, isalary),
'max_salary': max_salary,
'min_salary': min_salary
'max_salary': self._max_salary(data),
'min_salary': self._min_salary(data)
}

def stats(self, data, iage, isalary):
Expand Down
26 changes: 26 additions & 0 deletions tests/test_datastats.py
Expand Up @@ -99,3 +99,29 @@ def test__avg_yearly_increase():
ds = DataStats()

assert ds._avg_yearly_increase(test_data, 20, 20000) == 837


def test__max_salary():

ds = DataStats()

assert ds._max_salary(test_data) == [{
"id": 3,
"name": "Garth",
"surname": "Fields",
"age": 70,
"salary": "£70472"
}]


def test__min_salary():

ds = DataStats()

assert ds._min_salary(test_data) == [{
"id": 1,
"name": "Laith",
"surname": "Simmons",
"age": 68,
"salary": "£27888"
}]

0 comments on commit 17b2413

Please sign in to comment.