summaryrefslogtreecommitdiff
path: root/Homework/cs5300/homework-two/InfixTest.py
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5300/homework-two/InfixTest.py
downloadmisc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.tar.gz
misc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.zip
Diffstat (limited to 'Homework/cs5300/homework-two/InfixTest.py')
-rw-r--r--Homework/cs5300/homework-two/InfixTest.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/Homework/cs5300/homework-two/InfixTest.py b/Homework/cs5300/homework-two/InfixTest.py
new file mode 100644
index 0000000..826085d
--- /dev/null
+++ b/Homework/cs5300/homework-two/InfixTest.py
@@ -0,0 +1,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')