Advertisement
Guest User

Autochecker

a guest
Oct 23rd, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. import re, subprocess, random, time, os, sys
  2.  
  3. def openFile(fname):
  4.    f = open(fname)
  5.    input = f.read()
  6.    f.close()
  7.    return re.sub('[^a-zA-Z .,?!]+', '', input)
  8.  
  9. def generateString(input):
  10.    startChar = random.randint(1, len(input)-170)
  11.    return input[startChar:startChar+random.randint(0,160)]
  12.  
  13. def testString(str):
  14.    f = open("input.txt", "wb")
  15.    f.write(str)
  16.    f.close()
  17.    print("Testing string:" + str)
  18.    cout = subprocess.check_output("./a.out",shell=True)
  19.    mipsout = subprocess.check_output("java -jar Mars.jar sm nc punctuation_checker.s",shell=True)
  20.    if (mipsout[-1:] == '\n'):
  21.       mipsout = mipsout[:-1] #trailing newline on MARS output
  22.    if mipsout == cout:
  23.       print "Passed."
  24.       print ""
  25.    else:
  26.       print "FAILED"
  27.       sys.exit("stopped due to mismatch between C and MIPS output")
  28.  
  29. f = openFile(sys.argv[1])
  30. while 1:
  31.    str = generateString(f)
  32.    testString(str)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement