-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathunit_test.py
38 lines (33 loc) · 1.29 KB
/
unit_test.py
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
34
35
36
37
38
from colorama import Fore
from colorama import Style
TEXT_SUCCESSFUL = "{}succesful{}!".format(Fore.GREEN, Style.RESET_ALL)
def test_failed(output):
return "{}{}{}!".format(Fore.RED, output, Style.RESET_ALL)
def test_multiple(func,tests):
for entry in tests:
value = entry[0]
expected = entry[1]
actual = func(*value)
if actual == expected:
print("Test [{}] {}".format(str(value), TEXT_SUCCESSFUL))
else:
print(test_failed("Test [{}] failed! Expected {} but calculated {} ...".format(str(value),expected,actual)))
break
else:
print("All tests successful!")
def test(func,test,name):
value = test[0]
expected = test[1]
actual = func(value)
if actual == expected:
print("Test [{}] {}".format(name, TEXT_SUCCESSFUL))
else:
print(test_failed("Test [{}] failed! Expected {} but calculated {} ...".format(name,expected,actual)))
return
def test_instance_method(instance_method_call, expected, name):
actual = instance_method_call
if actual == expected:
print("Test [{}] {}".format(str(name), TEXT_SUCCESSFUL))
else:
print(test_failed("Test [{}] failed! Expected {} but calculated {} ...".format(str(name),expected,actual)))
return