-
Notifications
You must be signed in to change notification settings - Fork 0
/
testcases.py
executable file
·52 lines (42 loc) · 993 Bytes
/
testcases.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3
__author__ = "Fabian Golle <me@fabian-golle.de>"
__copyright__ = "Fabian Golle <me@fabian-golle.de>"
__version__ = "1.0"
__revision__ = "f0b3ab7"
__status__ = "Production"
def abort(message):
print(message)
quit()
try:
from huvorffman import Huffman
from rle import RunLenghtEncoding
except Exception:
abort('Import-failure')
testcases = [
'abcdefghijklmnopqrstuvwxyz',
'äüöß',
'!"§$%&/()=?=)(/&%$§"',
'¡“¶¢[]|{}≠¿',
'1234567890',
];
i = 0
for t in testcases:
try:
huff = Huffman()
rl = RunLenghtEncoding()
encoded = huff.encode(t)
if (t != huff.decode(encoded)):
raise Exception
encoded = rl.encode(t)
decoded = rl.decode(encoded)
if (t != decoded):
raise Exception
except Exception as e:
print("Testcase failed!")
print("Input: "+str(t))
print("Output: "+str(decoded))
if (len(str(e)) > 0):
print('Exception: ' + str(e))
else:
i += 1
print(str(i)+' of '+str(len(testcases))+' Testcases succeed')