agile-tutorial
agile-tutorial copied to clipboard
Create `/math/add` resource
As a user I need to add an integer value to each element 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('/add/<int:integer>')
@math_ns.doc(params={'integer': 'Integer value.'}, description='Add integer value to list.')
class AddList(Resource):
def put(self, integer):
return ms.add_list(my_list, integer)
- The
main.pyfile should include an external file above thefrom src import basic_services as bsline.
from src import math_services as ms
- There should be a
src/math_services.pyfile with the following content
def add_list(integer_list, integer_value):
"""
Add an integer value to every integer in the list.
Receives
--------
integer_list : list
List of integers.
integer_value : integer
Integer value to be added to the list.
Returns
-------
added_list : list
List of integers added to input value.
"""
added_list = [x + integer_value for x in integer_list]
integer_list.clear()
integer_list.extend(added_list)
return integer_list
- There should be a
test/math_test.pyfile with the following content.
from src import math_services as ms
def test_add_list():
assert ms.add_list([], 1) == []
assert ms.add_list([1], 0) == [1]
assert ms.add_list([1], 1) == [2]
assert ms.add_list([1, 2], 1) == [2, 3]
assert ms.add_list([1, 2, 3], 1) == [2, 3, 4]
Acceptance criteria:
Given that the application stores a list of integers
When this resource is called
Then an integer value is added to each number in the list.