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

提交作业

上级 81495551
流水线 #156436 已通过 于阶段
用时 37 秒
...@@ -43,6 +43,80 @@ green = lambda text: '\033[0;32;1m' + text + '\033[0m' ...@@ -43,6 +43,80 @@ green = lambda text: '\033[0;32;1m' + text + '\033[0m'
yellow = lambda text: '\033[0;33;1m' + text + '\033[0m' yellow = lambda text: '\033[0;33;1m' + text + '\033[0m'
# 比较两个文件并把结果生成一份html文本 # 比较两个文件并把结果生成一份html文本
def compare_dat_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
returnVal = 0
if file1 == "" or file2 == "":
print('文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'.format(file1, file2))
sys.exit()
else:
print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ')
if os.path.isfile(file1) and os.path.isfile(file2):
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(file1, file2)
execResult = os.system(runCommand)
if execResult != 0:
print("文件不同")
exit(1)
else:
print("文件相同")
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))
else:
promptInfo = "Case{0} 验证成功, 分数: {1}".format(seqNum, int(score))
outputPromptInfo(bCI, promptInfo, Color.green)
if seqNum == caseCount:
promptInfo = "恭喜你通过了所有测试!"
outputPromptInfo(bCI, promptInfo, Color.green)
returnVal = 1
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
# ==============================================================================
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
# 比较两个文件并把结果生成一份html文本
def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType): def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
returnVal = 0 returnVal = 0
if file1 == "" or file2 == "": if file1 == "" or file2 == "":
...@@ -51,7 +125,14 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType): ...@@ -51,7 +125,14 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
else: else:
print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ') print("正在比较标准答案结果文件 {0} 和用户编写的应用程序结果文件 {1}".format(file1, file2), end=': ')
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2): if os.path.isfile(file1) and os.path.isfile(file2):
comResult = 0
if resultFileType == ResultFileType.writedat:
comResult = advanced_dat_file_compare(file1, file2)
else:
comResult = advanced_file_compare(file1, file2)
if comResult:
print("文件相同") print("文件相同")
score = 40 score = 40
if seqNum == caseCount: if seqNum == caseCount:
...@@ -220,9 +301,12 @@ if __name__ == "__main__": ...@@ -220,9 +301,12 @@ if __name__ == "__main__":
print("使用的数据源文件是 {0}。".format(dsFile)) print("使用的数据源文件是 {0}。".format(dsFile))
print("标准答案结果文件 {0}(左边)与用户编写的应用程序结果文件 {1}(右边)的比较结果:".format(resultFile, userresultFile)) print("标准答案结果文件 {0}(左边)与用户编写的应用程序结果文件 {1}(右边)的比较结果:".format(resultFile, userresultFile))
sys.stdout.flush()
runCommand = "diff {0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile) runCommand = "diff {0} {1} -b -B -y -i -W 100".format(resultFile, userresultFile)
execResult = os.system(runCommand) execResult = os.system(runCommand)
if execResult != 0:
print()
exit(1)
else: else:
if resultFileType != 3: if resultFileType != 3:
promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview" promptInfo = "查看文件比较结果可帮助你查找验证失败的原因。方法是:\n选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
......
  • Developer

    代码质量分析发现了 11 个问题。

    • 0 blocker
    • 🚫 0 critical
    • 2 major
    • 🔽 6 minor
    • 3 info

    注意: 存在下列问题的代码行在本次提交中没有发生变更,无法使用代码行评论的方式进行报告。所以将下列问题汇总显示在这里(点击问题链接可以转到对应的源代码行):

    1. [8 bytes in 1 blocks are definitely lost in loss record 1 of 1

    0x4C2DB8F: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) 0x40074A: main (main.c:10)](https://www.codecode.net/engintime-cs/teacher-group/shx/Test/casegroup/template/readargv-dat-writefile-dat/blob/c697fc7f4b53b5146d87ba70a3b177b26721c157/main.c#L10) 📘

    1. Memory leak: p 📘
    2. 🔽 Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project's include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config. (ProjectKey-176964) 📘
    3. 🔽 Variable 'b' is assigned a value that is never used. 📘
    4. 🔽 Variable 'p' is allocated memory that is never used. 📘
    5. 🔽 Either the condition 'fp2!=0' is redundant or there is possible null pointer dereference: fp2. 📘
    6. 🔽 Unused variable: buf 📘
    7. 🔽 Either the condition 'fp!=0' is redundant or there is possible null pointer dereference: fp. 📘
    8. keyword 'if' not followed by a single space 📘
    9. closing curly bracket not in the same line or column 📘
    10. closing curly bracket not in the same line or column 📘
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论