forked from jarun/bcal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
executable file
·125 lines (113 loc) · 6.04 KB
/
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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
'''
bcal (Byte CALculator) test script
Author: Arun Prakash Jana
Email : [email protected]
Home : https://github.com/jarun/bcal
NOTES:
1. Use the `-l` (light mode) option to print and
verify against minimal output in decimal bytes
2. Before raising a PR,
a. add relevant test cases
b. run `make test`
'''
import subprocess
test = [
('./bcal', '-m', '10', 'mb'), # 1
('./bcal', '-m', '10', 'TiB'), # 2
('./bcal', '-m', '.1', ' KIb '), # 3
('./bcal', '-m', '.1', 'KB '), # 4
('./bcal', '-m', '10', 'lb'), # 5
('./bcal', '-m', "0x4 kb * 2 + 5 mib"), # 6
('./bcal', '-m', "5*5*5*5 mIB"), # 7
('./bcal', '-m', "5mb*5*5*5"), # 8
('./bcal', '-m', "5 tb / 12"), # 9
('./bcal', '-m', "2kb+3mb/4*5+5*56mb"), # 10
('./bcal', '-m', "( 5 * 3) * (4 * 7 b)"), # 11
('./bcal', '-m', "( 5 * 3 + 8) * (4 * 7 b)"), # 12
('./bcal', '-m', "( 5 * (3 + 8 )) * (4 * 7 b )"), # 13
('./bcal', '-m', "( 5 ) * 2 mib"), # 14
('./bcal', '-m', "3 mb - 2 mib"), # 15
('./bcal', '-m', "2mb-3mib"), # 16
('./bcal', '-m', "2 mib * -2"), # 17
('./bcal', '-m', "2mib*-2"), # 18
('./bcal', '-m', "2giB*2/2"), # 19
('./bcal', '-m', "2qB*2"), # 20
('./bcal', '-m', "((2giB)*2/2)"), # 21
('./bcal', '-m', "((2giB)*(2/2)"), # 22
('./bcal', '-m', "((2giB)*1)/(2/2))"), # 23
('./bcal', '-m', "((2giB)*1)/(2/2)"), # 24
('./bcal', '-m', "(((2giB)*)2/2)"), # 25
('./bcal', '-m', '0xffffffffffffffffffffffffffffffff', 'b'), # 26
('./bcal', '-m', "2b / 3"), # 27
('./bcal', '-m', "2 kIb/((3 ) )"), # 28
('./bcal', '-m', "2 gIb/ - 3"), # 29
('./bcal', '-m', "(2) kIb/((3))"), # 30
('./bcal', '-m', "(2) 4 kIb/((3))"), # 31
('./bcal', '-m', "(2) 4 kIb/((3))(2)"), # 32
('./bcal', '-m', "2 / 3 tib "), # 33
('./bcal', '-m', " 1000 "), # 34
('./bcal', '-m', " 0x1234mib "), # 35
('./bcal', '-m', " "), # 36
('./bcal', '-m', "0x18mb"), # 37
('./bcal', '-m', "0x18mb", "kb"), # 38
('./bcal', '-m', "0x18mb82"), # 39
('./bcal', '-m', "0x18mbc4"), # 40
('./bcal', '-m', "0x18mb 82"), # 41
('./bcal', '-m', "0x18mb", "82"), # 42
]
res = [
b'10000000\n', # 1
b'10995116277760\n', # 2
b'102\n', # 3
b'100\n', # 4
b'ERROR: unknown unit\n', # 5
b'5250880\n', # 6
b'655360000\n', # 7
b'625000000\n', # 8
b'416666666666\n', # 9
b'283752000\n', # 10
b'420\n', # 11
b'644\n', # 12
b'1540\n', # 13
b'10485760\n', # 14
b'902848\n', # 15
b'ERROR: negative result\n', # 16
b'ERROR: negative token\n', # 17
b'ERROR: negative token\n', # 18
b'2147483648\n', # 19
b'ERROR: unknown unit\n', # 20
b'2147483648\n', # 21
b'ERROR: unbalanced expression\n', # 22
b'ERROR: unbalanced expression\n', # 23
b'2147483648\n', # 24
b'ERROR: invalid token\n', # 25
b'340282366920938463463374607431768211455\n', # 26
b'0\n', # 27
b'682\n', # 28
b'ERROR: negative token\n', # 29
b'ERROR: invalid expression\n', # 30
b'ERROR: invalid expression\n', # 31
b'ERROR: invalid expression\n', # 32
b'ERROR: unit mismatch in /\n', # 33
b'1000\n', # 34
b'4886364160\n', # 35
b'ERROR: invalid value\n', # 36
b'24000000\n', # 37
b'ERROR: malformed input\n', # 38
b'ERROR: malformed input\n', # 39
b'ERROR: malformed input\n', # 40
b'ERROR: malformed input\n', # 41
b'ERROR: unknown unit\n', # 42
]
print()
for index, item in enumerate(test):
print('Executing test %d' % (int)(index + 1))
try:
out = subprocess.check_output(item, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
# print(e.output)
assert e.output == res[index]
else:
assert out == res[index]
print('\nAll good! :)')