Skip to content

Commit

Permalink
Testlib checker!
Browse files Browse the repository at this point in the history
  • Loading branch information
gi-b716 committed Nov 16, 2024
1 parent 2a1c717 commit dc9b7c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
13 changes: 12 additions & 1 deletion autoHack.infinite.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,18 @@
logger.info("Judging data {0}".format(globalCount))
result = data.runHacking(diffCount)

if result[1]==True:
if config.checkerFile != "" and config.useTestlib:
checkerResFile = open("checkerResult","r")
checkerRes = checkerResFile.read()
checkerResFile.close()
os.system("del checkerResult /q")
print("{0}".format(checkerRes))
logger.debug("{0} Exit code: {1}.".format(checkerRes.replace("\n"," | "),result[8]))
if result[0]==0:
time.sleep(config.waitTime)
diffCount += 1

elif result[1]==True:
os.system("move .\\{0} .\\hackData\\{0}".format(refer[0]))
os.system("move .\\{0} .\\hackData\\{0}".format(refer[1]))
os.system("cls")
Expand Down
13 changes: 12 additions & 1 deletion autoHack.random.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,18 @@
os.system("move .\\{0} .\\hackData\\{0}".format(refer[1]))
os.system("cls")

if result[1]==True:
if config.checkerFile != "" and config.useTestlib:
checkerResFile = open("checkerResult","r")
checkerRes = checkerResFile.read()
checkerResFile.close()
os.system("del checkerResult /q")
print("{0}".format(checkerRes))
logger.debug("{0} Exit code: {1}.".format(checkerRes.replace("\n"," | "),result[8]))
if result[0]==0:
time.sleep(config.waitTime)
diffCount += 1

elif result[1]==True:
print("Time Limit Exceeded on data {0}!".format(samplesId))
logger.warning("Time Limit Exceeded! On {0} and {1}, exceed {2} ms".format(refer[0],refer[1],result[2]))
time.sleep(config.waitTime)
Expand Down
18 changes: 14 additions & 4 deletions dataGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Config:
# Checker
checkerFile = ""
compileCheckerCommands = "g++ $(cname).cpp -o $(cname)"
runningCheckerCommands = ".\\$(cname) $(i) $(a) $(o)"
runningCheckerCommands = ".\\$(cname) $(i) $(o) $(a)"
useTestlib = False

# File
dataFileName = (("hack","in"),("hack","ans"))
Expand Down Expand Up @@ -133,6 +134,7 @@ def runHacking(self, id):
timeOutTag = False
memoryOutTag = False
exitCode = 0
checkerExitCode = 0
result = 0
ans = None
output = None
Expand Down Expand Up @@ -169,7 +171,15 @@ def runHacking(self, id):
ans = ansFile.read()
output = outputFile.read()

if self.config.checkerFile != "":
if self.config.checkerFile != "" and self.config.useTestlib:
runCheckerCommand = "{0} 2> checkerResult".format(self.config.runningCheckerCommands.replace("$(cname)",self.config.checkerFile).replace("$(i)",freInputFileName).replace("$(a)",ansFileName).replace("$(o)",freOutputFileName))
checkerExitCode = os.system("{0}".format(runCheckerCommand))
if checkerExitCode == 0:
result = 1
else:
result = 0

elif self.config.checkerFile != "":
runCheckerCommand = self.config.runningCheckerCommands.replace("$(cname)",self.config.checkerFile).replace("$(i)",freInputFileName).replace("$(a)",ansFileName).replace("$(o)",freOutputFileName)
result = os.system("{0}".format(runCheckerCommand))

Expand Down Expand Up @@ -206,7 +216,7 @@ def runHacking(self, id):
os.system("rename {0} {1}".format(freInputFileName,inputFileName))
os.system("del {0} /q".format(freOutputFileName))

return [result,timeOutTag,self.config.timeLimits,ans,output,exitCode,memoryOutTag,self.config.memoryLimits]
return [result,timeOutTag,self.config.timeLimits,ans,output,exitCode,memoryOutTag,self.config.memoryLimits,checkerExitCode]

class Test:
def __init__(self):
Expand Down Expand Up @@ -322,7 +332,7 @@ def mainPage(self):
self.mainPage()

class Meta:
_version = "6.0.0" # Update!
_version = "6.1.0"


if __name__ == "__main__":
Expand Down

0 comments on commit dc9b7c0

Please sign in to comment.