This repository was archived by the owner on Jul 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
This repository was archived by the owner on Jul 22, 2024. It is now read-only.
Create /math/power resource #21
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
As a user
I need to power each element in the list by an integer value
So that so that calculations can be automated.
Assumptions:
- There should be a
main.pyfile with the following content.
@math_ns.route('/power/<int:integer>')
@math_ns.doc(params={'integer': 'Integer value.'}, description='Power list to an integer.')
class PowerList(Resource):
def put(self, integer):
return ms.power_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 power_list(integer_list, integer_value):
"""
Power every integer in the list to an integer value.
Receives
--------
integer_list : list
List of integers.
integer_value : integer
Integer value to which every element should be powered.
Returns
-------
powered_list : list
List of integers powered to input value.
"""
powered_list = [x**integer_value for x in integer_list]
integer_list.clear()
integer_list.extend(powered_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_power_list():
assert ms.power_list([], 1) == []
assert ms.power_list([1], 0) == [1]
assert ms.power_list([1], 1) == [1]
assert ms.power_list([1], 2) == [1]
assert ms.power_list([1], 3) == [1]
assert ms.power_list([1, 2], 0) == [1, 1]
assert ms.power_list([1, 2], 1) == [1, 2]
assert ms.power_list([1, 2], 2) == [1, 4]
assert ms.power_list([1, 2], 3) == [1, 8]
assert ms.power_list([1, 2, 3], 0) == [1, 1, 1]
assert ms.power_list([1, 2, 3], 1) == [1, 2, 3]
assert ms.power_list([1, 2, 3], 2) == [1, 4, 9]
assert ms.power_list([1, 2, 3], 3) == [1, 8, 27]Acceptance criteria:
Given that the application stores a list of integers
When this resource is called
Then each number in the list is powered to an integer value.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request