提交 4b5f3b83 创建 作者: 宋海霞's avatar 宋海霞

提交作业

上级 ad602ec6
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
from comtool import *
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFileStr.format(1), userresultFileStr.format(1))
runCommand = "make && valgrind --xml=yes --xml-file=./build/valgrind-report.xml {0}".format(runProgCmdStr)
runCmd(runCommand)
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import os
import platform
import sys
from enum import Enum
execProgStr = sys.argv[1]
class DataSourceFileType(Enum):
noinput = 0
input = 1
readtxt = 2
readdat = 3
class ResultFileType(Enum):
nooutput = 0
output = 1
writetxt = 2
writedat = 3
class PlatformType(Enum):
other = 0
windows = 1
linux = 2
# 读取文件
def read_file(file_name):
try:
file_desc = open(file_name, 'r')
# 读取后按行分割
text = file_desc.read().splitlines()
file_desc.close()
return text
except IOError as error:
print('Read input file Error: {0}'.format(error))
sys.exit()
# 比较时忽略行末的空格和文件末尾的回车换行
def advanced_file_compare(file1, file2):
f1 = open(file1)
f2 = open(file2)
returnVal = 1
str1 = []
for line1 in f1:
line1 = line1.rstrip()
line1 = line1.replace('\n', '')
if len(line1) != 0:
str1.append(line1)
str2 = []
for line2 in f2:
line2 = line2.rstrip()
line2 = line2.replace('\n', '')
if len(line2) != 0:
str2.append(line2)
count = 0
if len(str1) == len(str2):
for line1 in str1:
if line1 != str2[count]: #文件不同
returnVal = 0
break
else:
count = count + 1
else:
returnVal = 0
f1.close()
f2.close()
return returnVal
def advanced_dat_file_compare(file1, file2):
returnVal = 1
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(file1, file2)
execResult = os.system(runCommand)
if execResult != 0:
returnVal = 0
return returnVal
def getPlatformType():
platformType = PlatformType.other
if platform.system().lower() == 'windows':
platformType = PlatformType.windows
elif platform.system().lower() == 'linux':
platformType = PlatformType.linux
else:
platformType = PlatformType.other
return platformType
def getProjInfo():
dsType = getDataSourceFileType()
dsFileStr = getDataSourceFileStr(dsType)
resultFileType = getResultFileType()
resultFileStr = getResultFileStr(resultFileType)
userresultFileStr = getUserResultFileStr(resultFileType)
return dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr
def getDataSourceFileType():
dsType = DataSourceFileType.noinput
if os.path.isfile("input1.txt"):
dsType = DataSourceFileType.input
elif os.path.isfile("readfile1.txt"):
dsType = DataSourceFileType.readtxt
elif os.path.isfile("readfile1.dat"):
dsType = DataSourceFileType.readdat
else:
dsType = DataSourceFileType.noinput
return dsType
def getDataSourceFileStr(dataSourceFileType):
dsType = dataSourceFileType
dsFileStr = ""
if dsType == DataSourceFileType.readtxt:
dsFileStr = "readfile{0}.txt"
elif dsType == DataSourceFileType.readdat:
dsFileStr = "readfile{0}.dat"
elif dsType == DataSourceFileType.input:
dsFileStr = "input{0}.txt"
return dsFileStr
def getResultFileType():
resultFileType = 0
if os.path.isfile("output1.txt"):
resultFileType = ResultFileType.output
elif os.path.isfile("writefile1.txt"):
resultFileType = ResultFileType.writetxt
elif os.path.isfile("writefile1.dat"):
resultFileType = ResultFileType.writedat
else:
resultFileType = ResultFileType.nooutput
return resultFileType
def getResultFileStr(resultFileType):
resultFileStr = ""
type = resultFileType
if type == ResultFileType.output:
resultFileStr = "output{0}.txt"
elif type == ResultFileType.writetxt:
resultFileStr = "writefile{0}.txt"
elif type == ResultFileType.writedat:
resultFileStr = "writefile{0}.dat"
return resultFileStr
def getUserResultFileStr(resultFileType):
userresultFileStr = ""
type = resultFileType
if type == ResultFileType.output:
userresultFileStr = "user_output{0}.txt"
elif type == ResultFileType.writetxt:
userresultFileStr = "user_writefile{0}.txt"
elif type == ResultFileType.writedat:
userresultFileStr = "user_writefile{0}.dat"
return userresultFileStr
def getSpecifyfileStr():
specifyFile = ""
if os.path.isfile("file.dat"):
specifyFile = "file.dat"
elif os.path.isfile("file.txt"):
specifyFile = "file.txt"
return specifyFile
def getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile):
global execProgStr
inresultFileStr = ""
if dsType == DataSourceFileType.input:
if resultFileType == ResultFileType.output:
inresultFileStr = " < {0} > {1} ".format(dsFile, userresultFile)
elif resultFileType == ResultFileType.writedat or resultFileType == ResultFileType.writetxt:
inresultFileStr = " {1} < {0} ".format(dsFile, userresultFile)
elif dsType == DataSourceFileType.readtxt or dsType == DataSourceFileType.readdat:
if resultFileType == ResultFileType.output:
inresultFileStr = " {0} > {1} ".format(dsFile, userresultFile)
elif resultFileType == ResultFileType.writedat or resultFileType == ResultFileType.writetxt:
inresultFileStr = " {0} {1} ".format(dsFile, userresultFile)
else:
if resultFileType == ResultFileType.output:
inresultFileStr = " > {0} ".format(userresultFile)
elif resultFileType == ResultFileType.writedat or resultFileType == ResultFileType.writetxt:
inresultFileStr = " {0} ".format(userresultFile)
runCommandStr = execProgStr
runCommandStr += inresultFileStr
return runCommandStr
def runCmd(cmdStr):
print("正在执行命令: {0}".format(cmdStr))
sys.stdout.flush()
execResult = os.system(cmdStr)
if execResult != 0:
exit(1)
import sys
import argparse
import os
import filecmp
import subprocess
import platform
from comtool import *
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFileStr.format(1), userresultFileStr.format(1))
runCommandStr = "valgrind --leak-check=full {0}".format(runProgCmdStr)
if platform.system().lower() == 'windows':
runCommandStr = "make && drmemory -ignore_kernel -leaks_only -brief -batch -- {0}".format(runProgCmdStr)
runCmd(runCommandStr)
......@@ -5,16 +5,15 @@
"label": "生成项目(make)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目 ; make"
"command": "cmd.exe /c type \"'${execPath}.tips\\env_tip.txt'\" ; echo \"`\" ; cmd.exe /c echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目 ; cmd.exe /c type \"'${execPath}.tips\\make_tip.txt'\" ; echo \"`\" ; make"
},
"linux": {
"command": "echo 正在使用makefile文件生成项目 && make && echo 生成项目成功"
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && echo 正在使用makefile文件生成项目 && echo VSCode安装路径-'${execPath}' && echo 正在使用makefile文件生成项目 && echo \"如果报告 ld.exe: cannot open output file ***.exe: Permission denied 错误,可以 重启 vscode 或者 重启计算机\" && make && echo 生成项目成功"
},
"args": [],
"group": "build",
"presentation": {
"reveal": "always",
"focus": true,
"group": "make"
},
"problemMatcher": "$gcc"
......@@ -23,10 +22,10 @@
"label": "安装python包",
"type": "shell",
"windows": {
"command": "pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
"command": "echo 更多帮助请参考https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md ; pip install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"linux": {
"command": "pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && pip3 install -i https://mirrors.aliyun.com/pypi/simple/ -r requirements.txt"
},
"args": [],
"group": "build",
......@@ -40,10 +39,10 @@
"label": "测试(test)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\test.py"
"command": "cmd.exe /c type \"'${execPath}.tips\\python_tip.txt'\" ; echo \"`\" ; python .vscode\\test.py .\\app.exe"
},
"linux": {
"command": "python3 .vscode/test.py"
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && python3 .vscode/test.py ./app.exe"
},
"args": [],
"group": "build",
......@@ -57,10 +56,10 @@
"label": "清理项目(make clean)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件清理项目 ; make clean"
"command": "cmd.exe /c type \"'${execPath}.tips\\env_tip.txt'\" ; echo \"`\" ; cmd.exe /c echo VSCode安装路径-${execPath} ; echo \"`\" ; echo 正在使用makefile文件清理项目 ; make clean"
},
"linux": {
"command": "echo 正在使用makefile文件清理项目 && make clean && echo 清理项目成功"
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && echo 正在使用makefile文件清理项目 && make clean && echo 清理项目成功"
},
"args": [],
"group": "build",
......@@ -74,10 +73,10 @@
"label": "提交作业(git push)",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\python_tip.txt\" ; python .vscode\\gitpush.py"
"command": "cmd.exe /c type \"'${execPath}.tips\\python_tip.txt'\" ; echo \"`\" ; python .vscode\\gitpush.py"
},
"linux": {
"command": "python3 .vscode/gitpush.py"
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && python3 .vscode/gitpush.py"
},
"args": [],
"group": "build",
......@@ -91,11 +90,11 @@
"label": "内存检测",
"type": "shell",
"windows": {
"command": "cat \"${execPath}.tips\\env_tip.txt\" ; echo VSCode安装路径-${execPath} ; echo 正在使用Dr.Memory检测内存 ; make ; cmd.exe /c \"drmemory -ignore_kernel -leaks_only -brief -batch -- .\\app.exe '<' input1.txt\""
"command": "cmd.exe /c type \"'${execPath}.tips\\env_tip.txt'\" ; echo \"`\" ; cmd.exe /c echo VSCode安装路径-${execPath} ; echo \"`\" ; echo 正在使用Dr.Memory检测内存 ; python .vscode/memorycheck.py .\\app.exe"
},
"linux": {
"command": "echo 正在使用 Valgrind 检测内存 && make && echo ***如果提示 /bin/bash: valgrind: command not found 可使用终端命令 sudo apt install valgrind 安装(需要连接互联网)*** && valgrind --leak-check=full ./app.exe < input1.txt"
},
"command": "echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md && echo 正在使用 Valgrind 检测内存 && make && echo ***如果提示 /bin/bash: valgrind: command not found 可使用终端命令 sudo apt install valgrind 安装(需要连接互联网)*** && python3 .vscode/memorycheck.py ./app.exe"
},
"args": [],
"group": "build",
"presentation": {
......
#!/bin/env python
# -*- coding: utf-8 -*-
import argparse
import difflib
import filecmp
import os
import platform
import subprocess
import sys
import webbrowser
from enum import Enum
from comtool import *
class CmpFileType:
unknown = 0
templatedatasource = 1
templateresult = 2
userprojresult = 3
def getFileCount(fileStr):
fileCount = 1
while 1:
resultFile = fileStr.format(fileCount)
if not os.path.isfile(resultFile):
fileCount -= 1
break
fileCount += 1
return fileCount
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, type):
returnVal = 0
bDat = False
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
resultFileType = getResultFileType()
dsFileType = getDataSourceFileType()
if type == CmpFileType.userprojresult:
promptInfo = "正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}"
if resultFileType == ResultFileType.writedat:
bDat = True
elif type == CmpFileType.templateresult:
promptInfo = "正在比较模板中的标准答案结果文件 {0} 和用户程序中的标准答案结果文件 {1}"
if resultFileType == ResultFileType.writedat:
bDat = True
elif type == CmpFileType.templatedatasource:
promptInfo = "正在比较模板中的数据源文件 {0} 和用户程序中的数据源文件 {1}"
if dsFileType == DataSourceFileType.readdat:
bDat = True
print(promptInfo.format(file1, file2), end=': ')
sys.stdout.flush()
if os.path.isfile(file1) and os.path.isfile(file2):
comResult = 0
if bDat:
comResult = advanced_dat_file_compare(file1, file2)
else:
comResult = advanced_file_compare(file1, file2)
if comResult == 1:
print("文件相同")
print()
sys.stdout.flush()
returnVal = 1
else:
print("文件不同")
print()
sys.stdout.flush()
return returnVal
if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
# 检查数据源文件一致性
dsFileCount = getFileCount(dsFileStr)
for i in range(1, dsFileCount + 1):
dsFile = dsFileStr.format(i)
userresultFile = userresultFileStr.format(i)
runProgCommand = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCommand)
print("正在检查{0}文件的一致性".format(dsFile))
sys.stdout.flush()
if compare_file("template/{0}".format(dsFile), dsFile, CmpFileType.templatedatasource) == 0:
runCmpCommand = "diff template/{0} {0} -b -B -y -i --suppress-common-lines".format(dsFile)
runCmd(runCmpCommand)
exit(1)
# 检查输出文件的一致性
resultFileCount = getFileCount(resultFileStr)
for i in range(1, resultFileCount + 1):
dsFile = dsFileStr.format(i)
userresultFile = userresultFileStr.format(i)
runProgCommand = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCommand)
resultFile = resultFileStr.format(i)
print("正在检查{0}文件的一致性".format(resultFile))
sys.stdout.flush()
if compare_file( "template/{0}".format(resultFile), resultFile, CmpFileType.templateresult) == 0:
runCmpCommand = "diff template/{0} {0} -b -B -y -i --suppress-common-lines".format(resultFile)
runCmd(runCmpCommand)
exit(1)
# 执行完成文件完整性检查
os.system("fileidentity.sh")
if sys.argv[2] != "":
# 克隆教师检查项目,参数:${CODECODE_PROTOCOL}gitlab-ci-token:${CI_JOB_TOKEN}@${CODECODE_DOMAIN}/${TEACHERCHECK_REPO}
runCloneCommand = "git clone {0} teacher_check".format(sys.argv[3])
runCmd(runCloneCommand)
teaCheckCount = getFileCount("teacher_check/" + dsFileStr)
for i in range(1, teaCheckCount + 1):
print("正在检查附加算例case{0}".format(i))
sys.stdout.flush()
# runProgCommand = "./app.exe < teacher_check/input{0}.txt > user_output{0}.txt".format(i)
# execResult = os.system(runProgCommand)
dsFile = "teacher_check/{0}".format(dsFileStr.format(i))
userresultFile = userresultFileStr.format(i)
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
runCmd(runProgCmdStr)
resultFile = resultFileStr.format(i)
if compare_file( "teacher_check/{0}".format(resultFile), userresultFile, CmpFileType.userprojresult) == 0:
runCmpCommand = "diff teacher_check/{0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
runCmd(runCmpCommand)
exit(1)
# 处理读取指定文件
if teaCheckCount == 0:
specifyfile = getSpecifyfileStr()
if os.path.isfile("teacher_check/" + specifyfile):
runCpCommand = "cp teacher_check/{0} {0}".format(specifyfile)
runCmd(runCpCommand)
print("正在检查附加算例")
userresultFile = userresultFileStr.format(1)
runProgCmdStr = getRunProgCmdStr(dsType, resultFileType, "", userresultFile)
runCmd(runProgCmdStr)
resultFile = resultFileStr.format(1)
if compare_file( "teacher_check/{0}".format(resultFile), userresultFile, CmpFileType.userprojresult) == 0:
runCmpCommand = "diff teacher_check/{0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
runCmd(runCmpCommand)
exit(1)
# 执行完成附加算例检查
os.system("extracase.sh")
\ No newline at end of file
......@@ -10,11 +10,22 @@ import filecmp
import subprocess
import platform
bIncludeCi = False
if len(sys.argv) > 1 and sys.argv[1] == "ci":
bIncludeCi = True
from enum import Enum
if bIncludeCi == False:
from comtool import *
class Color(Enum):
white = 0
green = 1
red = 2
yellow = 3
bCI = False
if len(sys.argv) > 2 and sys.argv[2] == "ci":
bCI = True
if bCI == False:
print(
"************************************************************\n"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,\n"
......@@ -31,218 +42,205 @@ red = lambda text: '\033[0;31;1m' + text + '\033[0m'
green = lambda text: '\033[0;32;1m' + text + '\033[0m'
yellow = lambda text: '\033[0;33;1m' + text + '\033[0m'
# 读取文件
def read_file(file_name):
try:
file_desc = open(file_name, 'r')
# 读取后按行分割
text = file_desc.read().splitlines()
file_desc.close()
return text
except IOError as error:
print('Read input file Error: {0}'.format(error))
sys.exit()
# 比较时忽略行末的空格和文件末尾的回车换行
def advanced_file_compare(file1, file2):
f1 = open(file1)
f2 = open(file2)
returnVal = 1
str1 = []
for line1 in f1:
line1 = line1.rstrip()
line1 = line1.replace('\n', '')
if len(line1) != 0:
str1.append(line1)
str2 = []
for line2 in f2:
line2 = line2.rstrip()
line2 = line2.replace('\n', '')
if len(line2) != 0:
str2.append(line2)
count = 0
if len(str1) == len(str2):
for line1 in str1:
if line1 != str2[count]: #文件不同
returnVal = 0
break
else:
count = count + 1
else:
returnVal = 0
f1.close()
f2.close()
return returnVal
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum, caseCount, bIncludeCi):
def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.stdout.flush()
sys.exit()
else:
print("正在比较标准答案输出文件 {0} 和用户编写的应用程序输出文件 {1}".format(file1, file2), end=': ')
print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ')
sys.stdout.flush()
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
score = 40
if seqNum == caseCount:
score = 100
if os.path.isfile(file1) and os.path.isfile(file2):
comResult = 0
if resultFileType == ResultFileType.writedat:
comResult = advanced_dat_file_compare(file1, file2)
else:
score = score + 60 / caseCount * seqNum
comResult = advanced_file_compare(file1, file2)
if bIncludeCi :
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 1)
print("exec-score", int(score))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bIncludeCi, promptInfo, 1)
if comResult:
print("文件相同")
score = 40
if seqNum == caseCount:
score = 100
else:
score = score + 60 / caseCount * seqNum
if bCI :
promptInfo = "Case{0} 验证成功".format(seqNum)
outputPromptInfo(bCI, promptInfo, Color.green)
print("exec-score", int(score))
print()
sys.stdout.flush()
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bCI, promptInfo, Color.green)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
outputPromptInfo(bIncludeCi, promptInfo, 1)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
outputPromptInfo(bCI, promptInfo, Color.green)
returnVal = 1
return returnVal
else:
print("文件不同")
promptInfo = "Case{0} 验证失败".format(seqNum)
outputPromptInfo(bIncludeCi, promptInfo, 2)
if bIncludeCi == False:
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
promptContent = "<p>Case {0} 验证失败。使用的标准输入文件是 intput{0}.txt。</br>标准答案输出文件 output{0}.txt(左边)与用户编写的应用程序输出文件 user_output{0}.txt(右边)的比较结果:</p>".format(seqNum)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
returnVal = 1
return returnVal
else:
return returnVal
else:
print("文件不同")
promptInfo = "Case{0} 验证失败".format(seqNum)
outputPromptInfo(bCI, promptInfo, Color.green)
if bCI == False and resultFileType != ResultFileType.writedat:
text1_lines = read_file(file1)
text2_lines = read_file(file2)
diff = difflib.HtmlDiff() # 创建HtmlDiff 对象
result = diff.make_file(text1_lines, text2_lines) # 通过make_file 方法输出 html 格式的对比结果
# 将结果写入到result_comparation.html文件中
try:
with open('result_comparation.html', 'a+', encoding="utf-8") as result_file:
dsFile = getDataSourceFileStr(dsType).format(seqNum)
resultfile = getResultFileStr(resultFileType).format(seqNum)
userresultfile = getUserResultFileStr(resultFileType).format(seqNum)
promptContent = "<p>Case {0} 验证失败。使用的数据源文件是 {1}。</br>标准答案结果文件 {2}(左边)与用户编写的应用程序结果文件 {3}(右边)的比较结果:</p>".format(seqNum, dsFile, resultfile, userresultfile)
result = promptContent + result
result_file.write(result)
except IOError as error:
print('写入html文件错误:{0}'.format(error))
finally:
return returnVal
else:
return returnVal
# 1表示绿色,2表示红色,3表示黄色
def outputPromptInfo(bIncludeCi, promptInfo, color):
def outputPromptInfo(bCI, promptInfo, color):
if bIncludeCi :
if color == 1:
if bCI :
if color == Color.green:
print(green(promptInfo))
elif color == 2:
elif color == Color.red:
print(red(promptInfo))
elif color == 3:
elif color == Color.yellow:
print(yellow(promptInfo))
else:
print(promptInfo)
sys.stdout.flush()
else:
if color == 1:
if color == Color.green:
print(Fore.GREEN + promptInfo, file = stream)
elif color == 2:
elif color == Color.red:
print(Fore.RED + promptInfo, file = stream)
elif color == 3:
elif color == Color.yellow:
print(Fore.YELLOW + promptInfo, file = stream)
else:
print(promptInfo)
print(Fore.WHITE, file = stream)
sys.stdout.flush()
if __name__ == "__main__":
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
promptInfo = "正在使用 makefile 文件生成项目"
outputPromptInfo(bIncludeCi, promptInfo, 1)
outputPromptInfo(bCI, promptInfo, Color.green)
execResult = os.system("make")
if execResult != 0:
errorInfo = "生成项目失败"
outputPromptInfo(bIncludeCi, errorInfo, 2)
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
else:
score = 40
if not os.path.isfile("output1.txt"):
if not os.path.isfile("output1.txt") and not os.path.isfile("writefile1.txt") and not os.path.isfile("writefile1.dat"):
score = 100
if bIncludeCi:
if bCI:
promptInfo = "生成项目成功"
outputPromptInfo(bIncludeCi, promptInfo, 1)
outputPromptInfo(bCI, promptInfo, Color.green)
promptInfo = "exec-score {0}".format(score)
print(promptInfo)
print()
sys.stdout.flush()
else:
promptInfo = "生成项目成功, 分数 {0}".format(score)
outputPromptInfo(bIncludeCi, promptInfo, 1)
outputPromptInfo(bCI, promptInfo, Color.green)
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
if resultFileType == ResultFileType.nooutput:
exit(0)
# 获取case的数量
caseCount = 1
while 1:
outputFile = "output{0}.txt".format(caseCount)
if not os.path.isfile(outputFile):
resultFile = resultFileStr.format(caseCount)
if not os.path.isfile(resultFile):
caseCount -= 1
break
caseCount += 1
if caseCount > 0:
if bCI :
print(yellow("标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。"))
else:
print(Fore.YELLOW + "标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。", file = stream, end='')
print(Fore.WHITE, file = stream)
seqNum = 1
while 1:
inputFile = "input{0}.txt".format(seqNum)
outputFile = "output{0}.txt".format(seqNum)
useroutputFile = "user_output{0}.txt".format(seqNum)
if seqNum == 1 and not os.path.isfile(outputFile):
while 1:
dsFile = dsFileStr.format(seqNum)
resultFile = resultFileStr.format(seqNum)
userresultFile = userresultFileStr.format(seqNum)
if seqNum == 1 and not os.path.isfile(resultFile):
promptInfo = "该项目未提供自动化验证功能"
if bIncludeCi :
if bCI :
print(red(promptInfo))
else:
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(outputFile):
if not os.path.isfile(resultFile):
break
print("正在使用文件 {0} 验证 case{1}".format(inputFile, seqNum))
runCommand = "./app.exe < {0} > {1}".format(inputFile, useroutputFile)
if platform.system().lower() == 'windows':
runCommand = "app.exe < {0} > {1}".format(inputFile, useroutputFile)
if dsType == DataSourceFileType.noinput:
print("正在验证 case{0}".format(seqNum))
else:
print("正在使用数据源文件 {0} 验证 case{1}".format(dsFile, seqNum))
promptInfo = "执行的命令是: {0}".format(runCommand)
outputPromptInfo(bIncludeCi, promptInfo, 0)
runCmdStr =getRunProgCmdStr(dsType, resultFileType, dsFile, userresultFile)
promptInfo = "正在执行命令: {0}".format(runCmdStr)
outputPromptInfo(bCI, promptInfo, Color.white)
if bIncludeCi == False:
if bCI == False:
promptInfo = "提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
outputPromptInfo(bIncludeCi, promptInfo, 3)
outputPromptInfo(bCI, promptInfo, Color.yellow)
execResult = os.system(runCommand)
execResult = os.system(runCmdStr)
if execResult != 0:
errorInfo = "应用程序执行异常,返回值:{0}。".format(execResult)
outputPromptInfo(bIncludeCi, errorInfo, 2)
outputPromptInfo(bCI, errorInfo, Color.red)
exit(1)
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum, caseCount, bIncludeCi) == 0:
if bIncludeCi :
print("使用的标准输入文件是 intput{0}.txt。\n标准答案输出文件 output{1}.txt(左边)与用户编写的应用程序输出文件 user_output{2}.txt(右边)的比较结果:".format(seqNum, seqNum, seqNum))
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(outputFile, useroutputFile)
if os.path.isfile(resultFile) and os.path.isfile(userresultFile):
if compare_file(resultFile, userresultFile, seqNum, caseCount, bCI, resultFileType, dsType) == 0:
if bCI :
if dsType != DataSourceFileType.noinput:
print("使用的数据源文件是 {0}。".format(dsFile))
print("标准答案结果文件 {0}(左边)与用户编写的应用程序结果文件 {1}(右边)的比较结果:".format(resultFile, userresultFile))
sys.stdout.flush()
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
execResult = os.system(runCommand)
if execResult != 0:
print()
exit(1)
else:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
outputPromptInfo(bIncludeCi, promptInfo, 2)
if resultFileType != ResultFileType.writedat:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
else:
promptInfo = "选择 View 菜单中的 Explorer 打开文件列表,右键点击 writefile*.dat文件或user_writefile*.dat文件,在弹出的菜单中选择 Open With...,再选择 Hex Editor "
outputPromptInfo(bCI, promptInfo, Color.red)
exit(1)
seqNum = seqNum + 1
......@@ -26,5 +26,6 @@ int main()
}
}
cout << endl;
free(z);
return 0;
}
......@@ -15,7 +15,7 @@ CFLAGS = -g -w -fmax-errors=10 -std=c++11 -fsigned-char -I${DIR_INC}
${BIN_TARGET}:${OBJ}
@echo --- build executable file: $@
$(CC) $(OBJ) -o $@
$(CC) $(OBJ) -o $@ -lm
${DIR_OBJ}/%.o:${DIR_SRC}/%.cpp
@echo --- build object file: $@
......@@ -32,4 +32,4 @@ else
endif
clean:
$(RM) *.exe *.o result_comparation.html user_output*
\ No newline at end of file
$(RM) *.exe *.o result_comparation.html user_*
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论