This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Create /math/variance resource #27
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
As a user
I need to calculate the variance 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('/variance')
@math_ns.doc(description='Variance of the list.')
class VarianceList(Resource):
def get(self):
return ms.variance(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 variance(integer_list):
"""
Calculates the variance of the list of integers.
Receives
--------
integer_list : list
List of integers.
Returns
-------
var : float
Variance of the list.
"""
integer_array = np.array(integer_list, dtype=int)
return np.var(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_variance():
assert ms.variance([1]) == 0.0
assert ms.variance([2]) == 0.0
assert ms.variance([1, 1]) == 0.0
assert ms.variance([1, 2]) == 0.25
assert ms.variance([1, 2, 3]) == 0.6666666666666666
assert ms.variance([0, 1, 2, 2]) == 0.6875
assert ms.variance([1, 1, 2, 3]) == 0.6875
assert ms.variance([1, 2, 4, 5]) == 2.5
assert ms.variance([1, 2, 3, 4, 5]) == 2.0Acceptance criteria:
Given that the application stores a list of integers
When this resource is called
Then the variance of the list is calculated.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request