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

Create `/math/subtract` resource

Open neumannrf opened this issue 6 years ago • 0 comments

As a user I need to subtract an integer value from each element 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('/subtract/<int:integer>')
@math_ns.doc(params={'integer': 'Integer value.'}, description='Subtract integer value to list.')
class SubtractList(Resource):
    def put(self, integer):
        return ms.subtract_list(my_list, integer)
  • 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
  • There should be a src/math_services.py file with the following content
def subtract_list(integer_list, integer_value):
    """
    Subtract an integer value to every integer in the list.

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

    integer_value : integer
        Integer value to be subtracted from the list.

    Returns
    -------
    subtracted_list : list
        List of integers subtracted to input value.
    """

    subtracted_list = [x - integer_value for x in integer_list]
    integer_list.clear()
    integer_list.extend(subtracted_list)
    return integer_list
  • There should be a test/math_test.py file with the following content.
from src import math_services as ms


def test_subtract_list():
    assert ms.subtract_list([], 1) == []
    assert ms.subtract_list([1], 0) == [1]
    assert ms.subtract_list([1], 1) == [0]
    assert ms.subtract_list([1, 2], 1) == [0, 1]
    assert ms.subtract_list([1, 2, 3], 1) == [0, 1, 2]

Acceptance criteria:

Given that the application stores a list of integers
When this resource is called
Then an integer value is subtracted from each number in the list.

neumannrf avatar Mar 15 '19 14:03 neumannrf