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

Create 'math_mutiply' endpoints #40

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class DoubleList(Resource):
def put(self):
return ms.double_list(my_list)


@api.route('/answer')
@api.doc(description='The Answer to the Ultimate Question of Life, the Universe, and Everything.')
class TheAnswer(Resource):
Expand Down Expand Up @@ -66,6 +65,12 @@ def put(self, integer, position):
my_list.insert(position, integer)
return my_list

@math_ns.route('/multiply/<int:integer>')
@math_ns.doc(params={'integer': 'Integer value.'}, description='Multiply list by an integer.')
class MultiplyList(Resource):
def put(self, integer):
return ms.multiply_list(my_list, integer)

port = os.getenv('PORT', '5000')
if __name__ == "__main__":
app.run(host='0.0.0.0', port=int(port))
app.run(host='0.0.0.0', port=int(port))
19 changes: 11 additions & 8 deletions src/math_services.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
def double_list(integer_list):
def multiply_list(integer_list, integer_value):
"""
Multiplies every integer in the list by 2.
Multiply every integer in the list by an integer value.

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

integer_value : integer
Integer value by which every element should be multiplied.

Returns
-------
doubled_list : list
List of integer values multiplied by 2.
multiplied_list : list
List of integers multiplied by input value.
"""

doubled_list = [2*x for x in integer_list]
multiplied_list = [integer_value*x for x in integer_list]
integer_list.clear()
integer_list.extend(doubled_list)
return integer_list
integer_list.extend(multiplied_list)
return integer_list
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A falta de um linha em branco no final deste arquivo está gerando o erro src/math_services.py:22:24: W292 no newline at end of file.

12 changes: 12 additions & 0 deletions test/math_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ def test_double_list():
assert ms.double_list([2]) == [4]
assert ms.double_list([1, 2]) == [2, 4]
assert ms.double_list([1, 2, 3]) == [2, 4, 6]

def test_multiply_list():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O flake8 espera encontrar 2 linhas em branco entre uma função e a outra, gerando o erro test/math_test.py:11:1: E302 expected 2 blank lines, found 1.

assert ms.multiply_list([], 1) == []
assert ms.multiply_list([1], 0) == [0]
assert ms.multiply_list([1], 1) == [1]
assert ms.multiply_list([1], 2) == [2]
assert ms.multiply_list([1, 2], 0) == [0, 0]
assert ms.multiply_list([1, 2], 1) == [1, 2]
assert ms.multiply_list([1, 2], 2) == [2, 4]
assert ms.multiply_list([1, 2, 3], 0) == [0, 0, 0]
assert ms.multiply_list([1, 2, 3], 1) == [1, 2, 3]
assert ms.multiply_list([1, 2, 3], 2) == [2, 4, 6]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A falta de um linha em branco no final deste arquivo está gerando o erro test/math_test.py:21:55: W292 no newline at end of file.