Skip to content

Instantly share code, notes, and snippets.

@khafatech
Created April 29, 2013 20:57
Show Gist options
  • Select an option

  • Save khafatech/5484719 to your computer and use it in GitHub Desktop.

Select an option

Save khafatech/5484719 to your computer and use it in GitHub Desktop.
test parser.sml csc430
#!/usr/bin/env python
import os
P = True
F = False
tests = {"1;" : P,
"(1);" : P,
"1;\n2;" : P,
"(1;" : F,
"42);" : F,
"(((1))" : F,
"5*5;" : P,
}
def get_output_str(res):
if res == 0:
return "no error"
else:
return "error detected"
num_tests = len(tests.keys())
num_pass = 0
def run_test(input_str, expected_result):
global num_pass
res = os.system("echo '%s' | sml parser.sml 1> /dev/null" % input_str)
pass_or_fail = ""
if (res == 0 and expected_result) or \
(res != 0 and not expected_result):
pass_or_fail = "Pass"
num_pass += 1
else:
pass_or_fail = "Fail"
print "%s => %s\t\t\t%s" % (input_str, get_output_str(res), pass_or_fail)
print "----"
for test_string in tests:
run_test(test_string, tests[test_string])
print "\npassed:", num_pass
print "failed:", num_tests - num_pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment