From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- Homework/cs5300/homework-two/InfixTest.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Homework/cs5300/homework-two/InfixTest.py (limited to 'Homework/cs5300/homework-two/InfixTest.py') 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') -- cgit v1.3