Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
T
test-vscode-cpp-win
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸大学计算机学院
教师群组
宋海霞-shx
Test
test-vscode-cpp-win
提交
4b5f3b83
提交
4b5f3b83
5月 27, 2021
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
提交作业
上级
ad602ec6
隐藏空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
557 行增加
和
157 行删除
+557
-157
comtool.cpython-38.pyc
.vscode/__pycache__/comtool.cpython-38.pyc
+0
-0
code-analysis.py
.vscode/code-analysis.py
+25
-0
comtool.py
.vscode/comtool.py
+195
-0
memorycheck.py
.vscode/memorycheck.py
+22
-0
tasks.json
.vscode/tasks.json
+13
-14
teacher-check.py
.vscode/teacher-check.py
+160
-0
test.py
.vscode/test.py
+138
-140
main.cpp
main.cpp
+1
-0
makefile
makefile
+3
-3
没有找到文件。
.vscode/__pycache__/comtool.cpython-38.pyc
0 → 100644
浏览文件 @
4b5f3b83
添加文件
.vscode/code-analysis.py
0 → 100644
浏览文件 @
4b5f3b83
#!/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
.vscode/comtool.py
0 → 100644
浏览文件 @
4b5f3b83
#!/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
)
.vscode/memorycheck.py
0 → 100644
浏览文件 @
4b5f3b83
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
)
.vscode/tasks.json
浏览文件 @
4b5f3b83
...
@@ -5,16 +5,15 @@
...
@@ -5,16 +5,15 @@
"label"
:
"生成项目(make)"
,
"label"
:
"生成项目(make)"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"windows"
:
{
"command"
:
"c
at
\"
${execPath}.tips
\\
env_tip.txt
\"
; echo VSCode安装路径-${execPath} ; echo 正在使用makefile文件生成项目
; make"
"command"
:
"c
md.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"
:
{
"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"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
"presentation"
:
{
"presentation"
:
{
"reveal"
:
"always"
,
"reveal"
:
"always"
,
"focus"
:
true
,
"group"
:
"make"
"group"
:
"make"
},
},
"problemMatcher"
:
"$gcc"
"problemMatcher"
:
"$gcc"
...
@@ -23,10 +22,10 @@
...
@@ -23,10 +22,10 @@
"label"
:
"安装python包"
,
"label"
:
"安装python包"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"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"
:
{
"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"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
...
@@ -40,10 +39,10 @@
...
@@ -40,10 +39,10 @@
"label"
:
"测试(test)"
,
"label"
:
"测试(test)"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"windows"
:
{
"command"
:
"c
at
\"
${execPath}.tips
\\
python_tip.txt
\"
; python .vscode
\\
test.py
"
"command"
:
"c
md.exe /c type
\"
'${execPath}.tips
\\
python_tip.txt'
\"
; echo
\"
`
\"
; python .vscode
\\
test.py .
\\
app.exe
"
},
},
"linux"
:
{
"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"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
...
@@ -57,10 +56,10 @@
...
@@ -57,10 +56,10 @@
"label"
:
"清理项目(make clean)"
,
"label"
:
"清理项目(make clean)"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"windows"
:
{
"command"
:
"c
at
\"
${execPath}.tips
\\
env_tip.txt
\"
; echo VSCode安装路径-${execPath}
; echo 正在使用makefile文件清理项目 ; make clean"
"command"
:
"c
md.exe /c type
\"
'${execPath}.tips
\\
env_tip.txt'
\"
; echo
\"
`
\"
; cmd.exe /c echo VSCode安装路径-${execPath} ; echo
\"
`
\"
; echo 正在使用makefile文件清理项目 ; make clean"
},
},
"linux"
:
{
"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"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
...
@@ -74,10 +73,10 @@
...
@@ -74,10 +73,10 @@
"label"
:
"提交作业(git push)"
,
"label"
:
"提交作业(git push)"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"windows"
:
{
"command"
:
"c
at
\"
${execPath}.tips
\\
python_tip.txt
\"
; python .vscode
\\
gitpush.py"
"command"
:
"c
md.exe /c type
\"
'${execPath}.tips
\\
python_tip.txt'
\"
; echo
\"
`
\"
; python .vscode
\\
gitpush.py"
},
},
"linux"
:
{
"linux"
:
{
"command"
:
"python3 .vscode/gitpush.py"
"command"
:
"
echo 更多帮助请参考 https://www.codecode.net/engintime/codecode/publicmanual/blob/master/VSCodeFAQ.md &&
python3 .vscode/gitpush.py"
},
},
"args"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
...
@@ -91,11 +90,11 @@
...
@@ -91,11 +90,11 @@
"label"
:
"内存检测"
,
"label"
:
"内存检测"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"windows"
:
{
"windows"
:
{
"command"
:
"c
at
\"
${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"
:
"c
md.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"
:
{
"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"
:
[],
"args"
:
[],
"group"
:
"build"
,
"group"
:
"build"
,
"presentation"
:
{
"presentation"
:
{
...
...
.vscode/teacher-check.py
0 → 100644
浏览文件 @
4b5f3b83
#!/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
.vscode/test.py
浏览文件 @
4b5f3b83
...
@@ -10,11 +10,22 @@ import filecmp
...
@@ -10,11 +10,22 @@ import filecmp
import
subprocess
import
subprocess
import
platform
import
platform
bIncludeCi
=
False
from
enum
import
Enum
if
len
(
sys
.
argv
)
>
1
and
sys
.
argv
[
1
]
==
"ci"
:
bIncludeCi
=
True
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
(
print
(
"************************************************************
\n
"
"************************************************************
\n
"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,
\n
"
"如果下面报告类似 ImportError: No module named 'xxx' 的错误,
\n
"
...
@@ -31,218 +42,205 @@ red = lambda text: '\033[0;31;1m' + text + '\033[0m'
...
@@ -31,218 +42,205 @@ red = lambda text: '\033[0;31;1m' + text + '\033[0m'
green
=
lambda
text
:
'
\033
[0;32;1m'
+
text
+
'
\033
[0m'
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'
# 读取文件
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文本
# 比较两个文件并把结果生成一份html文本
def
compare_file
(
file1
,
file2
,
seqNum
,
caseCount
,
b
IncludeCi
):
def
compare_file
(
file1
,
file2
,
seqNum
,
caseCount
,
b
CI
,
resultFileType
,
dsType
):
returnVal
=
0
returnVal
=
0
if
file1
==
""
or
file2
==
""
:
if
file1
==
""
or
file2
==
""
:
print
(
'文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'
.
format
(
file1
,
file2
))
print
(
'文件路径不能为空:第一个文件的路径:{0}, 第二个文件的路径:{1} .'
.
format
(
file1
,
file2
))
sys
.
stdout
.
flush
()
sys
.
exit
()
sys
.
exit
()
else
:
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
):
if
os
.
path
.
isfile
(
file1
)
and
os
.
path
.
isfile
(
file2
):
print
(
"文件相同"
)
comResult
=
0
score
=
40
if
resultFileType
==
ResultFileType
.
writedat
:
if
seqNum
==
caseCount
:
comResult
=
advanced_dat_file_compare
(
file1
,
file2
)
score
=
100
else
:
else
:
score
=
score
+
60
/
caseCount
*
seqNum
comResult
=
advanced_file_compare
(
file1
,
file2
)
if
bIncludeCi
:
if
comResult
:
promptInfo
=
"Case{0} 验证成功"
.
format
(
seqNum
)
print
(
"文件相同"
)
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
1
)
score
=
40
print
(
"exec-score"
,
int
(
score
))
if
seqNum
==
caseCount
:
else
:
score
=
100
promptInfo
=
"Case{0} 验证成功, 分数: {1}"
.
format
(
seqNum
,
int
(
score
))
else
:
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
1
)
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
:
if
seqNum
==
caseCount
:
promptInfo
=
"恭喜你通过了所有测试!"
promptInfo
=
"恭喜你通过了所有测试!"
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
1
)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
returnVal
=
1
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
:
return
returnVal
return
returnVal
else
:
else
:
return
returnVal
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表示黄色
# 1表示绿色,2表示红色,3表示黄色
def
outputPromptInfo
(
b
IncludeCi
,
promptInfo
,
color
):
def
outputPromptInfo
(
b
CI
,
promptInfo
,
color
):
if
b
IncludeCi
:
if
b
CI
:
if
color
==
1
:
if
color
==
Color
.
green
:
print
(
green
(
promptInfo
))
print
(
green
(
promptInfo
))
elif
color
==
2
:
elif
color
==
Color
.
red
:
print
(
red
(
promptInfo
))
print
(
red
(
promptInfo
))
elif
color
==
3
:
elif
color
==
Color
.
yellow
:
print
(
yellow
(
promptInfo
))
print
(
yellow
(
promptInfo
))
else
:
else
:
print
(
promptInfo
)
print
(
promptInfo
)
sys
.
stdout
.
flush
()
else
:
else
:
if
color
==
1
:
if
color
==
Color
.
green
:
print
(
Fore
.
GREEN
+
promptInfo
,
file
=
stream
)
print
(
Fore
.
GREEN
+
promptInfo
,
file
=
stream
)
elif
color
==
2
:
elif
color
==
Color
.
red
:
print
(
Fore
.
RED
+
promptInfo
,
file
=
stream
)
print
(
Fore
.
RED
+
promptInfo
,
file
=
stream
)
elif
color
==
3
:
elif
color
==
Color
.
yellow
:
print
(
Fore
.
YELLOW
+
promptInfo
,
file
=
stream
)
print
(
Fore
.
YELLOW
+
promptInfo
,
file
=
stream
)
else
:
else
:
print
(
promptInfo
)
print
(
promptInfo
)
print
(
Fore
.
WHITE
,
file
=
stream
)
print
(
Fore
.
WHITE
,
file
=
stream
)
sys
.
stdout
.
flush
()
sys
.
stdout
.
flush
()
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
compResultFile
=
"result_comparation.html"
compResultFile
=
"result_comparation.html"
if
os
.
path
.
isfile
(
compResultFile
):
if
os
.
path
.
isfile
(
compResultFile
):
os
.
remove
(
compResultFile
)
os
.
remove
(
compResultFile
)
promptInfo
=
"正在使用 makefile 文件生成项目"
promptInfo
=
"正在使用 makefile 文件生成项目"
outputPromptInfo
(
b
IncludeCi
,
promptInfo
,
1
)
outputPromptInfo
(
b
CI
,
promptInfo
,
Color
.
green
)
execResult
=
os
.
system
(
"make"
)
execResult
=
os
.
system
(
"make"
)
if
execResult
!=
0
:
if
execResult
!=
0
:
errorInfo
=
"生成项目失败"
errorInfo
=
"生成项目失败"
outputPromptInfo
(
b
IncludeCi
,
errorInfo
,
2
)
outputPromptInfo
(
b
CI
,
errorInfo
,
Color
.
red
)
exit
(
1
)
exit
(
1
)
else
:
else
:
score
=
40
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
score
=
100
if
b
IncludeCi
:
if
b
CI
:
promptInfo
=
"生成项目成功"
promptInfo
=
"生成项目成功"
outputPromptInfo
(
b
IncludeCi
,
promptInfo
,
1
)
outputPromptInfo
(
b
CI
,
promptInfo
,
Color
.
green
)
promptInfo
=
"exec-score {0}"
.
format
(
score
)
promptInfo
=
"exec-score {0}"
.
format
(
score
)
print
(
promptInfo
)
print
(
promptInfo
)
print
()
sys
.
stdout
.
flush
()
else
:
else
:
promptInfo
=
"生成项目成功, 分数 {0}"
.
format
(
score
)
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的数量
# 获取case的数量
caseCount
=
1
caseCount
=
1
while
1
:
while
1
:
outputFile
=
"output{0}.txt"
.
format
(
caseCount
)
resultFile
=
resultFileStr
.
format
(
caseCount
)
if
not
os
.
path
.
isfile
(
outpu
tFile
):
if
not
os
.
path
.
isfile
(
resul
tFile
):
caseCount
-=
1
caseCount
-=
1
break
break
caseCount
+=
1
caseCount
+=
1
if
caseCount
>
0
:
if
bCI
:
print
(
yellow
(
"标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。"
))
else
:
print
(
Fore
.
YELLOW
+
"标准答案结果文件和用户输出结果文件的比较原则是:比较时忽略行尾空白字符和文件末尾的空白行。"
,
file
=
stream
,
end
=
''
)
print
(
Fore
.
WHITE
,
file
=
stream
)
seqNum
=
1
seqNum
=
1
while
1
:
while
1
:
inputFile
=
"input{0}.txt"
.
format
(
seqNum
)
dsFile
=
dsFileStr
.
format
(
seqNum
)
outputFile
=
"output{0}.txt"
.
format
(
seqNum
)
resultFile
=
resultFileStr
.
format
(
seqNum
)
user
outputFile
=
"user_output{0}.txt"
.
format
(
seqNum
)
user
resultFile
=
userresultFileStr
.
format
(
seqNum
)
if
seqNum
==
1
and
not
os
.
path
.
isfile
(
outpu
tFile
):
if
seqNum
==
1
and
not
os
.
path
.
isfile
(
resul
tFile
):
promptInfo
=
"该项目未提供自动化验证功能"
promptInfo
=
"该项目未提供自动化验证功能"
if
b
IncludeCi
:
if
b
CI
:
print
(
red
(
promptInfo
))
print
(
red
(
promptInfo
))
else
:
else
:
print
(
Fore
.
RED
+
"该项目未提供自动化验证功能"
,
file
=
stream
,
end
=
''
)
print
(
Fore
.
RED
+
"该项目未提供自动化验证功能"
,
file
=
stream
,
end
=
''
)
print
(
Fore
.
WHITE
,
file
=
stream
)
print
(
Fore
.
WHITE
,
file
=
stream
)
break
break
if
not
os
.
path
.
isfile
(
outpu
tFile
):
if
not
os
.
path
.
isfile
(
resul
tFile
):
break
break
print
(
"正在使用文件 {0} 验证 case{1}"
.
format
(
inputFile
,
seqNum
))
if
dsType
==
DataSourceFileType
.
noinput
:
runCommand
=
"./app.exe < {0} > {1}"
.
format
(
inputFile
,
useroutputFile
)
print
(
"正在验证 case{0}"
.
format
(
seqNum
)
)
if
platform
.
system
()
.
lower
()
==
'windows'
:
else
:
runCommand
=
"app.exe < {0} > {1}"
.
format
(
inputFile
,
useroutputFile
)
print
(
"正在使用数据源文件 {0} 验证 case{1}"
.
format
(
dsFile
,
seqNum
)
)
promptInfo
=
"执行的命令是: {0}"
.
format
(
runCommand
)
runCmdStr
=
getRunProgCmdStr
(
dsType
,
resultFileType
,
dsFile
,
userresultFile
)
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
0
)
promptInfo
=
"正在执行命令: {0}"
.
format
(
runCmdStr
)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
white
)
if
b
IncludeCi
==
False
:
if
b
CI
==
False
:
promptInfo
=
"提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
promptInfo
=
"提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
outputPromptInfo
(
b
IncludeCi
,
promptInfo
,
3
)
outputPromptInfo
(
b
CI
,
promptInfo
,
Color
.
yellow
)
execResult
=
os
.
system
(
runC
ommand
)
execResult
=
os
.
system
(
runC
mdStr
)
if
execResult
!=
0
:
if
execResult
!=
0
:
errorInfo
=
"应用程序执行异常,返回值:{0}。"
.
format
(
execResult
)
errorInfo
=
"应用程序执行异常,返回值:{0}。"
.
format
(
execResult
)
outputPromptInfo
(
b
IncludeCi
,
errorInfo
,
2
)
outputPromptInfo
(
b
CI
,
errorInfo
,
Color
.
red
)
exit
(
1
)
exit
(
1
)
if
os
.
path
.
isfile
(
outputFile
)
and
os
.
path
.
isfile
(
useroutputFile
):
if
os
.
path
.
isfile
(
resultFile
)
and
os
.
path
.
isfile
(
userresultFile
):
if
compare_file
(
outputFile
,
useroutputFile
,
seqNum
,
caseCount
,
bIncludeCi
)
==
0
:
if
compare_file
(
resultFile
,
userresultFile
,
seqNum
,
caseCount
,
bCI
,
resultFileType
,
dsType
)
==
0
:
if
bIncludeCi
:
if
bCI
:
print
(
"使用的标准输入文件是 intput{0}.txt。
\n
标准答案输出文件 output{1}.txt(左边)与用户编写的应用程序输出文件 user_output{2}.txt(右边)的比较结果:"
.
format
(
seqNum
,
seqNum
,
seqNum
))
if
dsType
!=
DataSourceFileType
.
noinput
:
runCommand
=
"diff {0} {1} -b -B -y -i -W 100"
.
format
(
outputFile
,
useroutputFile
)
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
)
execResult
=
os
.
system
(
runCommand
)
if
execResult
!=
0
:
print
()
exit
(
1
)
else
:
else
:
promptInfo
=
"查看文件比较结果可帮助你查找验证失败的原因。方法是:
\n
选择 View 菜单中的 Explorer 打开文件列表,右键点击 result_comparation.html 文件,在弹出的菜单中选择 Open Preview"
if
resultFileType
!=
ResultFileType
.
writedat
:
outputPromptInfo
(
bIncludeCi
,
promptInfo
,
2
)
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
)
exit
(
1
)
seqNum
=
seqNum
+
1
seqNum
=
seqNum
+
1
main.cpp
浏览文件 @
4b5f3b83
...
@@ -26,5 +26,6 @@ int main()
...
@@ -26,5 +26,6 @@ int main()
}
}
}
}
cout
<<
endl
;
cout
<<
endl
;
free
(
z
);
return
0
;
return
0
;
}
}
makefile
浏览文件 @
4b5f3b83
...
@@ -15,7 +15,7 @@ CFLAGS = -g -w -fmax-errors=10 -std=c++11 -fsigned-char -I${DIR_INC}
...
@@ -15,7 +15,7 @@ CFLAGS = -g -w -fmax-errors=10 -std=c++11 -fsigned-char -I${DIR_INC}
${BIN_TARGET}
:
${OBJ}
${BIN_TARGET}
:
${OBJ}
@
echo
---
build executable file:
$@
@
echo
---
build executable file:
$@
$(CC)
$(OBJ)
-o
$@
$(CC)
$(OBJ)
-o
$@
-lm
${DIR_OBJ}/%.o
:
${DIR_SRC}/%.cpp
${DIR_OBJ}/%.o
:
${DIR_SRC}/%.cpp
@
echo
---
build object file:
$@
@
echo
---
build object file:
$@
...
@@ -32,4 +32,4 @@ else
...
@@ -32,4 +32,4 @@ else
endif
endif
clean
:
clean
:
$(RM)
*
.exe
*
.o result_comparation.html user_output
*
$(RM)
*
.exe
*
.o result_comparation.html user_
*
\ No newline at end of file
\ No newline at end of file
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论