-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatlib_tester.py
69 lines (53 loc) · 2.3 KB
/
chatlib_tester.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import chatlib
def check_build(input_cmd, input_data, expected_output):
print("Input: ", input_cmd, input_data, "\nExpected output: ", expected_output)
try:
output = chatlib.build_message(input_cmd, input_data)
except Exception as e:
output = "Exception raised: " + str(e)
if output == expected_output:
print(".....\t SUCCESS")
else:
print(".....\t FAILED, output: ", output)
def check_parse(msg_str, expected_output):
print("Input: ", msg_str, "\nExpected output: ", expected_output)
try:
output = chatlib.parse_message(msg_str)
except Exception as e:
output = "Exception raised: " + str(e)
if output == expected_output:
print(".....\t SUCCESS")
else:
print(".....\t FAILED, output: ", output)
def main():
# BUILD
# Valid inputs
# Normal message
check_build("LOGIN", "aaaa#bbbb", "LOGIN |0009|aaaa#bbbb")
check_build("LOGIN", "aaaabbbb", "LOGIN |0008|aaaabbbb")
# Zero-length message
check_build("LOGIN", "", "LOGIN |0000|")
# Invalid inputs
# cmd too long
check_build("0123456789ABCDEFG", "", None)
# msg too long
check_build("A", "A" * (chatlib.MAX_DATA_LENGTH + 1), None)
# PARSE
# Valid inputs
check_parse("LOGIN | 9|aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse(" LOGIN | 9|aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse(" LOGIN| 9|aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse("LOGIN |9 |aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse("LOGIN | 09|aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse("LOGIN |0009|aaaa#bbbb", ("LOGIN", "aaaa#bbbb"))
check_parse("LOGIN |9 | aaa#bbbb", ("LOGIN", " aaa#bbbb"))
check_parse("LOGIN | 4|data", ("LOGIN", "data"))
# Invalid inputs
check_parse("", (None, None))
check_parse("LOGIN x 4|data", (None, None))
check_parse("LOGIN | 4xdata", (None, None))
check_parse("LOGIN | -4|data", (None, None))
check_parse("LOGIN | z|data", (None, None))
check_parse("LOGIN | 5|data", (None, None))
if __name__ == '__main__':
main()