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

modify

上级
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"preLaunchTask": "make",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
\ No newline at end of file
{
"version": "2.0.0",
"tasks": [
{
"label": "make",
"type": "shell",
"command": "make",
"args": [],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
\ No newline at end of file
添加文件
a=input();
x = eval(a);
if(x < 1):
y = x;
result = "x = {}, y = x = {}".format(x, y)
elif(x < 10):
y = 2 * x - 1;
result = "x = {}, y = 2 * x - 1 = {}".format(x, y)
else:
y = 3 * x - 11;
result = "x = {}, y = 3 * x - 11 = {}".format(x, y)
print (result);
// #include <iostream>
// using namespace std;
// int main()
// {
// cout << "Hello, world" << endl;
// return 0;
// }
#include <stdio.h>
int main()
{
int x, y;
scanf("%d", &x);
if(x < 1)
{
y = x;
printf("x = %d, y = x = %d\n \n \n ", x, y);
}
else if(x < 10)
{
y = 2 * x - 1;
printf("x = %d, y = 2 * x - 1 = %d\n \n \n ", x, y);
}
else
{
y = 3 * x - 11;
printf("x = %d, y = 3 * x - 11 = %d\n \n \n ", x, y);
}
return 0;
}
添加文件
-1
\ No newline at end of file
5
\ No newline at end of file
20
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
# 使用此文件的目录作为当前工作目录
os.chdir(os.path.dirname(__file__))
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
# 读取文件
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):
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) and filecmp.cmp(file1, file2):
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
print(Fore.GREEN + "Case{0} 验证成功".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
returnVal = 1
return returnVal
else:
print("文件不同")
print(Fore.RED + "Case{0} 验证失败".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
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:
return returnVal
if __name__ == "__main__":
print()
print(Fore.YELLOW + "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。", file = stream)
print(Fore.WHITE, file = stream)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
execResult = os.system("python3 --version")
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
exit(1)
print()
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
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):
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(outputFile):
break
print("正在使用文件 {0} 验证 case{1}".format(inputFile, seqNum))
runCommand = "python3 app.py < {0} > {1}".format(inputFile, useroutputFile)
execResult = os.system(runCommand)
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
break
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum) == 0:
print("正在使用浏览器打开文件比较结果,可帮助用户查找验证失败的原因。")
# 使用浏览器打开比较结果页面
webbrowser.open('file://' + os.path.realpath(compResultFile))
break
seqNum = seqNum + 1
\ No newline at end of file
#!/bin/env python
# -*- coding: utf-8 -*-
import difflib
import sys
import argparse
import webbrowser
import os
import filecmp
import subprocess
import platform
# 使用此文件的目录作为当前工作目录
os.chdir(os.path.dirname(__file__))
from colorama import Fore, init, AnsiToWin32
init(wrap=False)
stream = AnsiToWin32(sys.stderr).stream
# 读取文件
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):
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) and filecmp.cmp(file1, file2):
if os.path.isfile(file1) and os.path.isfile(file2) and advanced_file_compare(file1, file2):
print("文件相同")
print(Fore.GREEN + "Case{0} 验证成功".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
returnVal = 1
return returnVal
else:
print("文件不同")
print(Fore.RED + "Case{0} 验证失败".format(seqNum), file = stream, end='')
print(Fore.WHITE, file = stream)
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:
return returnVal
if __name__ == "__main__":
print()
print(Fore.YELLOW + "提示:\n1.如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序,修改应用程序后再验证。\n2.如果提示‘python’不是内部或外部命令,也不是可运行的程序或批处理文件。需要设置 Python 的环境变量并重启开发环境来解决此问题。", file = stream)
print(Fore.WHITE, file = stream)
print("开发环境中的 Python 解释器版本号:" + platform.python_version())
print("环境变量中的 Python 解释器版本号:", end=' ')
execResult = os.system("python3 --version")
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
exit(1)
print()
compResultFile = "result_comparation.html"
if os.path.isfile(compResultFile):
os.remove(compResultFile)
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):
print(Fore.RED + "该项目未提供自动化验证功能", file = stream, end='')
print(Fore.WHITE, file = stream)
break
if not os.path.isfile(outputFile):
break
print("正在使用文件 {0} 验证 case{1}".format(inputFile, seqNum))
runCommand = "make && ./app < {0} > {1}".format(inputFile, useroutputFile)
execResult = os.system(runCommand)
if execResult != 0:
print(Fore.RED + "应用程序异常,返回值:{0}。".format(execResult), file = stream, end='')
print(Fore.WHITE, file = stream)
break
if os.path.isfile(outputFile) and os.path.isfile(useroutputFile):
if compare_file(outputFile, useroutputFile, seqNum) == 0:
print("正在使用浏览器打开文件比较结果,可帮助用户查找验证失败的原因。")
# 使用浏览器打开比较结果页面
webbrowser.open('file://' + os.path.realpath(compResultFile))
break
seqNum = seqNum + 1
\ No newline at end of file
DIR_INC = .
DIR_SRC = .
DIR_OBJ = .
DIR_BIN = .
SRC = $(wildcard ${DIR_SRC}/*.c)
OBJ = $(patsubst %.c,${DIR_OBJ}/%.o,$(notdir ${SRC}))
TARGET = app.exe
BIN_TARGET = ${DIR_BIN}/${TARGET}
CC = gcc
CFLAGS = -g -w -fmax-errors=10 -std=c99 -fsigned-char -I${DIR_INC}
${BIN_TARGET}:${OBJ}
$(CC) $(OBJ) -o $@
${DIR_OBJ}/%.o:${DIR_SRC}/%.c
$(CC) $(CFLAGS) -c $< -o $@
\ No newline at end of file
x = -1, y = x = -5
\ No newline at end of file
x = 5, y = 2 * x - 1 = 9
\ No newline at end of file
x = 20, y = 3 * x - 11 = 49
\ No newline at end of file
<p>Case 1 验证失败。使用的标准输入文件是 intput1.txt。</br>标准答案输出文件 output1.txt(左边)与用户编写的应用程序输出文件 user_output1.txt(右边)的比较结果:</p>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
table.diff {font-family:Courier; border:medium;}
.diff_header {background-color:#e0e0e0}
td.diff_header {text-align:right}
.diff_next {background-color:#c0c0c0}
.diff_add {background-color:#aaffaa}
.diff_chg {background-color:#ffff77}
.diff_sub {background-color:#ffaaaa}
</style>
</head>
<body>
<table class="diff" id="difflib_chg_to0__top"
cellspacing="0" cellpadding="0" rules="groups" >
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
<colgroup></colgroup> <colgroup></colgroup> <colgroup></colgroup>
<tbody>
<tr><td class="diff_next" id="difflib_chg_to0__0"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="from0_1">1</td><td nowrap="nowrap">x&nbsp;=&nbsp;-1,&nbsp;y&nbsp;=&nbsp;x&nbsp;=&nbsp;-<span class="diff_chg">5</span></td><td class="diff_next"><a href="#difflib_chg_to0__top">t</a></td><td class="diff_header" id="to0_1">1</td><td nowrap="nowrap">x&nbsp;=&nbsp;-1,&nbsp;y&nbsp;=&nbsp;x&nbsp;=&nbsp;-<span class="diff_chg">1</span></td></tr>
<tr><td class="diff_next"></td><td class="diff_header"></td><td nowrap="nowrap"></td><td class="diff_next"></td><td class="diff_header" id="to0_2">2</td><td nowrap="nowrap"><span class="diff_add">&nbsp;&nbsp;</span></td></tr>
<tr><td class="diff_next"></td><td class="diff_header"></td><td nowrap="nowrap"></td><td class="diff_next"></td><td class="diff_header" id="to0_3">3</td><td nowrap="nowrap"><span class="diff_add">&nbsp;&nbsp;</span></td></tr>
<tr><td class="diff_next"></td><td class="diff_header"></td><td nowrap="nowrap"></td><td class="diff_next"></td><td class="diff_header" id="to0_4">4</td><td nowrap="nowrap"><span class="diff_add">&nbsp;&nbsp;&nbsp;&nbsp;</span></td></tr>
</tbody>
</table>
<table class="diff" summary="Legends">
<tr> <th colspan="2"> Legends </th> </tr>
<tr> <td> <table border="" summary="Colors">
<tr><th> Colors </th> </tr>
<tr><td class="diff_add">&nbsp;Added&nbsp;</td></tr>
<tr><td class="diff_chg">Changed</td> </tr>
<tr><td class="diff_sub">Deleted</td> </tr>
</table></td>
<td> <table border="" summary="Links">
<tr><th colspan="2"> Links </th> </tr>
<tr><td>(f)irst change</td> </tr>
<tr><td>(n)ext change</td> </tr>
<tr><td>(t)op</td> </tr>
</table></td> </tr>
</table>
</body>
</html>
\ No newline at end of file
x = -1, y = x = -1
\ No newline at end of file
x = 5, y = 2 * x - 1 = 9
\ No newline at end of file
x = 20, y = 3 * x - 11 = 49
\ No newline at end of file
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论