Create `/basic/unique` resource
Closed this issue · 0 comments
neumannrf commented
As a user
I need to eliminate duplicated elements from the list
So that a unique list of integers can be obtained.
Assumptions:
- There should be a
main.py
file with the following content.
@basic_ns.route('/unique')
@basic_ns.doc(description='Deduplicate list.')
class UniqueList(Resource):
def put(self):
bs.unique(my_list)
return my_list
- The
main.py
file should include an external file above thefrom src import default_services as ds
line.
from src import basic_services as bs
- There should be a
src/basic_services.py
file with the following content
def unique(integer_list):
"""
Remove duplicated elements from list.
Receives
--------
integer_list : list
List of integer values.
Returns
-------
unique_integer_list : list
List of unique integer values.
"""
integer_set = set(integer_list)
integer_list.clear()
integer_list.extend(list(integer_set))
return integer_list
- There should be a
test/basic_test.py
file with the following content.
from src import basic_services as bs
def test_unique():
assert bs.unique([]) == []
assert bs.unique([1]) == [1]
assert bs.unique([1, 1]) == [1]
assert bs.unique([1, 1, 1]) == [1]
assert bs.unique([1, 2, 1]) == [1, 2]
assert bs.unique([1, 2, 3]) == [1, 2, 3]
assert bs.unique([1, 2, 3, 1]) == [1, 2, 3]
assert bs.unique([1, 2, 3, 1, 2]) == [1, 2, 3]
assert bs.unique([1, 2, 3, 1, 2, 3]) == [1, 2, 3]
Acceptance criteria:
Given the existence of duplicated elements in the list
When this resource is called
Then only unique entries remain in the list.