-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lecture "Brute-force argorithms", exercise 2 #17
Comments
Without the use of deque() function
Using deque() function
|
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
# Test case for algorithm
def test(input_list, output_stack):
if input_list== output_stack:
return True
else:
return False
# Three different test runs
print (test(["Alice", "Bob", "Claire", "Danielle"], "Alice"))
print (test(["Alice", "Bob", "Claire", "Danielle"], ["Alice", "Danielle"]))
print (test(["Alice", "Bob", "Claire", "Danielle"], ["Alice", "Bob", "Claire", "Danielle"])) |
|
|
|
from collections import deque
def test_stack_from_list (input_list, expected):
if input_list == expected:
return True
else:
return False
def stack_from_list(input_list):
output_stack = deque()
for item in input_list:
output_stack.append(item)
return output_stack
#Test case
print (test_stack_from_list(["water", "tea", "coffee", "alcohol"], ["water", "tea", "coffee", "alcohol"]))
#Console output
True
`` |
from collections import deque
def test_stack_from_list(input_list, output_stack, expected):
result = stack_from_list(input_list) == deque(output_stack)
if expected == result:
return True
else:
return False
def stack_from_list(input_list):
output_stack = deque ()
for item in input_list:
output_stack.append(item)
return output_stack
print(test_stack_from_list((["a", "b", "c"]), (("a", "b")), False))
print(test_stack_from_list((["a", "b"]), (("a", "b")), True)) |
Test case for the algorithmdef test_stack_from_list (input_list, expected): from collections import deque
print(test_stack_from_list ([1, 2, 3, 4, 5], deque([1, 2, 3, 4, 5]))) |
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):
if stack_from_list(input_list) == expected:
return True
else:
return False
print(test_stack_from_list([0,1,2,3],deque([0,1,2,3])))
print(test_stack_from_list(['a','b','c','d'],deque(['a','b','c','d']))) |
|
|
Dear all, Just a reminder about test-driven development. All the tests must be passed to claim that an algorithm returns what is expected. If a test execution returns If you need to check the non-compliance of the execution of a function on purpose, then you have to create an additional testing function that returns True if the condition of the test is not passed. |
Create a test case for the algorithm introduced in Listing 2.
The text was updated successfully, but these errors were encountered: