-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest.py
More file actions
33 lines (28 loc) · 822 Bytes
/
test.py
File metadata and controls
33 lines (28 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import io
num_tests = 0
failed_tests = 0
def equal(expr, expected):
global num_tests
global failed_tests
num_tests += 1
if(expr == expected):
print("Test Passed with result: '", expr, "'", sep = '')
else:
failed_tests += 1
print("Failed!\n expected: '", expected, "'\n but got : '", expr, "'", sep = '')
return
def str_print(*objects):
out = io.StringIO()
print(*objects, file=out, end="")
res = out.getvalue()
return res
def output(*objects, expected=""):
out = str_print(*objects)
equal(out, expected)
return
def summary():
print("-------------------------------------------")
if failed_tests == 0:
print("All", num_tests, "passed!")
else:
print("{} out of {} tests failed!".format(failed_tests, num_tests))