Last active
August 29, 2015 14:11
-
-
Save kartikkukreja/3215b094650d0996b2cc to your computer and use it in GitHub Desktop.
Test Oracle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random, os | |
# define constants | |
correct_program = "correct.exe" | |
incorrect_program = "incorrect.exe" | |
input_file = "input.txt" | |
correct_output = "correct_output.txt" | |
incorrect_output = "incorrect_output.txt" | |
num_testcases = 10 | |
# generate test cases and write to input file | |
# create small, random test cases, consistent with the problem description | |
testcases = [random.random() for i in xrange(num_testcases)] | |
with open(input_file, 'w') as input_f: | |
for testcase in testcases: | |
# write test case to input file, consistent with the format described in the problem | |
input_f.write(str(testcase) + '\n') | |
# execute the two programs, resulting in them generating the output files | |
os.system(correct_program) | |
os.system(incorrect_program) | |
# compare the two output files and find a point of difference | |
with open(correct_output, 'r') as correct_f: | |
with open(incorrect_output, 'r') as incorrect_f: | |
for i in xrange(num_testcases): | |
# assuming that we output 1 line for each test case | |
# If multiple lines are output per test case, then all those should be read here | |
correct, incorrect = correct_f.readline(), incorrect_f.readline() | |
if correct != incorrect: | |
print testcases[i], "\ncorrect = ", correct, "\nincorrect = ", incorrect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment