blob: 826085dbc412ff43b5a28cb3b354dc490fc8e31a (
plain) (
blame)
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
|
#!/usr/bin/python
import os
i=1
def test(cmd, expected):
global i
stream = os.popen(cmd)
output = stream.read()
output = output.strip()
if output != expected:
print('Failed test {} ({}). Should have been "{}". Was "{}".'
.format(i, cmd, expected, output))
else:
print('Passed test {}.'.format(i))
i=i+1
# Compile the code
os.system('javac Infix.java')
# Run the tests. The first argument is the command to run
# and the second argument is the expected output of the
# program.
test('java Infix +12', '(1+2)')
test('java Infix -+121', '((1+2)-1)')
test('java Infix -+9-8+127', '((9+(8-(1+2)))-7)')
test('java Infix -+9-81+27', '((9+(8-1))-(2+7))')
test('java Infix +7', '(7+error')
test('java Infix -9+7', '(9-(7+error')
test('java Infix -+9-8+12', '((9+(8-(1+2)))-error')
test('java Infix -+9-a+127', '((9+(error')
test('java Infix -9-8+12+7', '(9-(8-(1+2)))error')
|