Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Create /math/standard_deviation resource #26

@neumannrf

Description

@neumannrf

As a user
I need to calculate the standard deviation of the elements in the list
So that so that calculations can be automated.

Assumptions:

  • There should be a main.py file with the following content.
@math_ns.route('/standard_deviation')
@math_ns.doc(description='Standard deviation of the list.')
class StandardDeviationList(Resource):
    def get(self):
        return ms.standard_deviation(my_list)
  • The main.py file should include an external file above the from src import basic_services as bs line.
from src import math_services as ms
  • The requirements.txt file should list numpy as a dependency.

  • There should be a src/math_services.py file with the following content

import numpy as np


def standard_deviation(integer_list):
    """
    Calculates the standard deviation of the list of integers.

    Receives
    --------
    integer_list : list
        List of integers.

    Returns
    -------
    std : float
        Standard deviation of the list.
    """

    integer_array = np.array(integer_list, dtype=int)
    return np.std(integer_array).astype(float)
  • There should be a test/math_test.py file with the following content.
from src import math_services as ms


def test_standard_deviation():
    assert ms.standard_deviation([1]) == 0.0
    assert ms.standard_deviation([2]) == 0.0
    assert ms.standard_deviation([1, 1]) == 0.0
    assert ms.standard_deviation([1, 2]) == 0.5
    assert ms.standard_deviation([1, 2, 3]) == 0.816496580927726
    assert ms.standard_deviation([0, 1, 2, 2]) == 0.82915619758885
    assert ms.standard_deviation([1, 1, 2, 3]) == 0.82915619758885
    assert ms.standard_deviation([1, 2, 4, 5]) == 1.5811388300841898
    assert ms.standard_deviation([1, 2, 3, 4, 5]) == 1.4142135623730951

Acceptance criteria:

Given that the application stores a list of integers
When this resource is called
Then the standard deviation of the list is calculated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions