agile-tutorial icon indicating copy to clipboard operation
agile-tutorial copied to clipboard

Create `/math/product` resource

Open neumannrf opened this issue 6 years ago • 0 comments

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

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

    Returns
    -------
    prod : float
        Product of the list.
    """

    integer_array = np.array(integer_list, dtype=int)
    return np.prod(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_product():
    assert ms.product([1]) == 1.0
    assert ms.product([2]) == 2.0
    assert ms.product([1, 1]) == 1.0
    assert ms.product([1, 2]) == 2.0
    assert ms.product([1, 2, 3]) == 6.0
    assert ms.product([0, 1, 2, 2]) == 0.0
    assert ms.product([1, 1, 2, 3]) == 6.0
    assert ms.product([1, 2, 4, 5]) == 40.0
    assert ms.product([1, 2, 3, 4, 5]) == 120.0

Acceptance criteria:

Given that the application stores a list of integers
When this resource is called
Then the product of the elements in the list is calculated.

neumannrf avatar Mar 15 '19 14:03 neumannrf