Lecture "Brute-force algorithms", exercise 2
Opened this issue ยท 7 comments
essepuntato commented
Create a test case for the algorithm introduced in Listing 2.
arcangelo7 commented
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
sntcristian commented
FrancescoFernicola commented
noreanystrom commented
essepuntato commented
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.
arimuti commented
morinigiu commented