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

Create /math/sum resource #28

Open
neumannrf opened this issue Mar 15, 2019 · 0 comments
Open

Create /math/sum resource #28

neumannrf opened this issue Mar 15, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@neumannrf
Copy link
Collaborator

As a user
I need to calculate the sum 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('/sum')
@math_ns.doc(description='Sum of the list.')
class SumList(Resource):
    def get(self):
        return ms.sum(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 sum(integer_list):
    """
    Calculates the sum of the list of integers.

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

    Returns
    -------
    sum : float
        Sum of the list.
    """

    integer_array = np.array(integer_list, dtype=int)
    return np.sum(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_sum():
    assert ms.sum([1]) == 1.0
    assert ms.sum([2]) == 2.0
    assert ms.sum([1, 1]) == 2.0
    assert ms.sum([1, 2]) == 3.0
    assert ms.sum([1, 2, 3]) == 6.0
    assert ms.sum([0, 1, 2, 2]) == 5.0
    assert ms.sum([1, 1, 2, 3]) == 7.0
    assert ms.sum([1, 2, 4, 5]) == 12.0
    assert ms.sum([1, 2, 3, 4, 5]) == 15.0

Acceptance criteria:

Given that the application stores a list of integers
When this resource is called
Then the sum of the elements in the list is calculated.
@neumannrf neumannrf added the enhancement New feature or request label Mar 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant