daily pastebin goal
36%
SHARE
TWEET

Autochecker

a guest Oct 23rd, 2018 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top