Open essepuntato opened 4 years ago
from collections import deque
def stack_from_list(input_list):
output_stack = deque()
for item in input_list:
output_stack.append(item)
return output_stack
def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)
if result == expected:
return True
else:
return False
print(test_stack_from_list([1, 2, 3, 4, 5], deque([1, 2, 3, 4, 5])))
# It prints True
Hi all,
please find attached my personal solution – also available online:
# Test case for the function
def test_stack_from_list(input_list, expected):
result = stack_from_list(input_list)
if expected == result:
return True
else:
return False
# 'stack_from_list' defined in Listing 2.
# Three different test runs
print(test_stack_from_list([], deque()))
print(test_stack_from_list([1, 2, 3, 4, 5], deque([1, 2, 3, 4, 5])))
Just a suggestion: when you test your code (any code, not just this exercise), please consider adding some tests which use borderline cases, such as using empty (but admissible) values, such as an empty list in this exercise.
The output is: True
Create a test case for the algorithm introduced in Listing 2.