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

提交作业

上级 c697fc7f
流水线 #156437 已通过 于阶段
用时 34 秒
......@@ -42,72 +42,6 @@ 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'
# 比较两个文件并把结果生成一份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)
......@@ -234,13 +168,9 @@ if __name__ == "__main__":
dsType, dsFileStr, resultFileType, userresultFileStr, resultFileStr = getProjInfo()
# resultFileType = getResultFileType()
if resultFileType == ResultFileType.nooutput:
exit(0)
# resultFileStr = getResultFileStr(resultFileType)
# userresultFileStr = getUserResultFileStr(resultFileType)
# 获取case的数量
caseCount = 1
while 1:
......@@ -250,8 +180,6 @@ if __name__ == "__main__":
break
caseCount += 1
# dsType = getDataSourceFileType()
# dsFileStr = getDataSourceFileStr(dsType)
seqNum = 1
while 1:
dsFile = dsFileStr.format(seqNum)
......
  • 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/47f0de2277972793889c0bbd31997fae18c2a63e/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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论