# lgiordani/datastats

Step 7 - Isolate max and min salary algorithms

• Loading branch information...
lgiordani committed Jul 15, 2017
1 parent 4005145 commit 17b24138e712f9174b072a579a2dfc9e2800e6ac
Showing with 34 additions and 6 deletions.
1. +8 −6 datastats/datastats.py
2. +26 −0 tests/test_datastats.py
 @@ -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):
 @@ -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.