Skip to content

Instantly share code, notes, and snippets.

@tuankiet65
Created December 6, 2014 12:13
Show Gist options
  • Save tuankiet65/9855b005957f06faa4a4 to your computer and use it in GitHub Desktop.
Save tuankiet65/9855b005957f06faa4a4 to your computer and use it in GitHub Desktop.
import random
import subprocess
import sys
flag=False
count=0
numA=0
numB=0
numNum=0
res=[]
def fail(res, resFile=None, runtimeError=False, e=None):
global count
global numA
global numB
with open('fail.txt', 'a') as f:
f.write('%d\n%d\n'%(numA, numB))
if resFile==None:
f.write('%s%s%s'%(res[0], res[1], res[2]))
else:
f.write('%s%s%s%s%s%s'%(res[0], resFile[0], res[1], resFile[1], res[2], resFile[2]))
if runtimeError:
print('Exit code %d, output:'%(e.returncode))
print(e.output.decode('utf-8'))
sys.exit()
f.write('----------------------------\n')
numTest=100
open('fail.txt', 'w')
while count!=numTest:
count+=1
random.seed()
numNum=random.randint(1, 5)
numA=random.randint(1, 10**numNum)
numB=random.randint(1, 10**numNum)
res=[str(numA+numB)+'\n', str(numA-numB)+'\n', str(numA*numB)+'\n']
with open('BIGNUM.INP', 'w') as f:
f.write('%d\n%d'%(numA, numB))
try:
subprocess.check_output('./bignum')
except subprocess.CalledProcessError as e:
fail(runtimeError=True, e=e, res=res)
with open('BIGNUM.OUT', 'r') as f:
resFile=f.readlines()
if resFile!=res:
fail(runtimeError=False, res=res, resFile=resFile)
print('\rTest ran: %d'%(count), end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment