agile-tutorial
agile-tutorial copied to clipboard
Create `/math/median` resource
As a user I need to calculate the median of the elements in the list So that so that calculations can be automated.
Assumptions:
- There should be a
main.pyfile with the following content.
@math_ns.route('/median')
@math_ns.doc(description='Median value of the list.')
class MedianList(Resource):
def get(self):
return ms.median(my_list)
- The
main.pyfile should include an external file above thefrom src import basic_services as bsline.
from src import math_services as ms
-
The
requirements.txtfile should listnumpyas a dependency. -
There should be a
src/math_services.pyfile with the following content
import numpy as np
def median(integer_list):
"""
Calculates the median of the list of integers.
Receives
--------
integer_list : list
List of integers.
Returns
-------
median : float
Median value of the list.
"""
integer_array = np.array(integer_list, dtype=int)
return np.median(integer_array).astype(float)
- There should be a
test/math_test.pyfile with the following content.
from src import math_services as ms
def test_median():
assert ms.median([1]) == 1.0
assert ms.median([2]) == 2.0
assert ms.median([1, 1]) == 1.0
assert ms.median([1, 2]) == 1.5
assert ms.median([1, 2, 3]) == 2.0
assert ms.median([0, 1, 2, 2]) == 1.5
assert ms.median([1, 1, 2, 3]) == 1.5
assert ms.median([1, 2, 4, 5]) == 3.0
assert ms.median([1, 2, 3, 4, 5]) == 3.0
Acceptance criteria:
Given that the application stores a list of integers
When this resource is called
Then the median of the list is calculated.