Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
read-pointfile-writefile-dat
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
问题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
银宸大学计算机学院
教师群组
宋海霞-shx
Test
casegroup
template
read-pointfile-writefile-dat
提交
fb01b31c
提交
fb01b31c
4月 12, 2021
创建
作者:
宋海霞
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
modify
上级
197b5992
流水线
#156444
已失败 于阶段
用时 10 秒
变更
1
流水线
1
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
41 行增加
和
30 行删除
+41
-30
test.py
.vscode/test.py
+41
-30
没有找到文件。
.vscode/test.py
浏览文件 @
fb01b31c
...
@@ -34,15 +34,22 @@ if bCI == False:
...
@@ -34,15 +34,22 @@ if bCI == False:
"************************************************************
\n
"
"************************************************************
\n
"
)
)
if
bCI
==
False
:
from
colorama
import
Fore
,
init
,
AnsiToWin32
from
colorama
import
Fore
,
init
,
AnsiToWin32
init
(
wrap
=
False
)
init
(
wrap
=
False
)
stream
=
AnsiToWin32
(
sys
.
stderr
)
.
stream
stream
=
AnsiToWin32
(
sys
.
stderr
)
.
stream
red
=
lambda
text
:
'
\033
[0;31;1m'
+
text
+
'
\033
[0m'
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
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文本
# 比较两个文件并把结果生成一份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
...
@@ -52,7 +59,14 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
...
@@ -52,7 +59,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
:
...
@@ -62,22 +76,22 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
...
@@ -62,22 +76,22 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
if
bCI
:
if
bCI
:
promptInfo
=
"Case{0} 验证成功"
.
format
(
seqNum
)
promptInfo
=
"Case{0} 验证成功"
.
format
(
seqNum
)
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
print
(
"exec-score"
,
int
(
score
))
print
(
"exec-score"
,
int
(
score
))
else
:
else
:
promptInfo
=
"Case{0} 验证成功, 分数: {1}"
.
format
(
seqNum
,
int
(
score
))
promptInfo
=
"Case{0} 验证成功, 分数: {1}"
.
format
(
seqNum
,
int
(
score
))
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
if
seqNum
==
caseCount
:
if
seqNum
==
caseCount
:
promptInfo
=
"恭喜你通过了所有测试!"
promptInfo
=
"恭喜你通过了所有测试!"
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
returnVal
=
1
returnVal
=
1
return
returnVal
return
returnVal
else
:
else
:
print
(
"文件不同"
)
print
(
"文件不同"
)
promptInfo
=
"Case{0} 验证失败"
.
format
(
seqNum
)
promptInfo
=
"Case{0} 验证失败"
.
format
(
seqNum
)
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
if
bCI
==
False
and
resultFileType
!=
ResultFileType
.
writedat
:
if
bCI
==
False
and
resultFileType
!=
ResultFileType
.
writedat
:
text1_lines
=
read_file
(
file1
)
text1_lines
=
read_file
(
file1
)
...
@@ -100,9 +114,9 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
...
@@ -100,9 +114,9 @@ def compare_file(file1, file2, seqNum, caseCount, bCI, resultFileType, dsType):
else
:
else
:
return
returnVal
return
returnVal
if
bCI
==
False
:
# 1表示绿色,2表示红色,3表示黄色
# 1表示绿色,2表示红色,3表示黄色
def
outputPromptInfo
(
bCI
,
promptInfo
,
color
):
def
outputPromptInfo
(
bCI
,
promptInfo
,
color
):
if
bCI
:
if
bCI
:
if
color
==
Color
.
green
:
if
color
==
Color
.
green
:
...
@@ -132,35 +146,31 @@ if __name__ == "__main__":
...
@@ -132,35 +146,31 @@ if __name__ == "__main__":
os
.
remove
(
compResultFile
)
os
.
remove
(
compResultFile
)
promptInfo
=
"正在使用 makefile 文件生成项目"
promptInfo
=
"正在使用 makefile 文件生成项目"
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
execResult
=
os
.
system
(
"make"
)
execResult
=
os
.
system
(
"make"
)
if
execResult
!=
0
:
if
execResult
!=
0
:
errorInfo
=
"生成项目失败"
errorInfo
=
"生成项目失败"
#
outputPromptInfo(bCI, errorInfo, Color.red)
outputPromptInfo
(
bCI
,
errorInfo
,
Color
.
red
)
exit
(
1
)
exit
(
1
)
else
:
else
:
score
=
40
score
=
40
if
not
(
os
.
path
.
isfile
(
"output1.txt"
)
or
os
.
path
.
isfile
(
"writefile1.txt"
)
or
os
.
path
.
isfile
(
"writefile1.dat"
)):
if
not
(
os
.
path
.
isfile
(
"output1.txt"
)
or
not
os
.
path
.
isfile
(
"writefile1.txt"
)
or
not
os
.
path
.
isfile
(
"writefile1.dat"
)):
score
=
100
score
=
100
if
bCI
:
if
bCI
:
promptInfo
=
"生成项目成功"
promptInfo
=
"生成项目成功"
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
promptInfo
=
"exec-score {0}"
.
format
(
score
)
promptInfo
=
"exec-score {0}"
.
format
(
score
)
print
(
promptInfo
)
print
(
promptInfo
)
else
:
else
:
promptInfo
=
"生成项目成功, 分数 {0}"
.
format
(
score
)
promptInfo
=
"生成项目成功, 分数 {0}"
.
format
(
score
)
#
outputPromptInfo(bCI, promptInfo, Color.green)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
green
)
dsType
,
dsFileStr
,
resultFileType
,
userresultFileStr
,
resultFileStr
=
getProjInfo
()
dsType
,
dsFileStr
,
resultFileType
,
userresultFileStr
,
resultFileStr
=
getProjInfo
()
# resultFileType = getResultFileType()
if
resultFileType
==
ResultFileType
.
nooutput
:
if
resultFileType
==
ResultFileType
.
nooutput
:
exit
(
0
)
exit
(
0
)
# resultFileStr = getResultFileStr(resultFileType)
# userresultFileStr = getUserResultFileStr(resultFileType)
# 获取case的数量
# 获取case的数量
caseCount
=
1
caseCount
=
1
while
1
:
while
1
:
...
@@ -170,8 +180,6 @@ if __name__ == "__main__":
...
@@ -170,8 +180,6 @@ if __name__ == "__main__":
break
break
caseCount
+=
1
caseCount
+=
1
# dsType = getDataSourceFileType()
# dsFileStr = getDataSourceFileStr(dsType)
seqNum
=
1
seqNum
=
1
while
1
:
while
1
:
dsFile
=
dsFileStr
.
format
(
seqNum
)
dsFile
=
dsFileStr
.
format
(
seqNum
)
...
@@ -181,9 +189,9 @@ if __name__ == "__main__":
...
@@ -181,9 +189,9 @@ if __name__ == "__main__":
promptInfo
=
"该项目未提供自动化验证功能"
promptInfo
=
"该项目未提供自动化验证功能"
if
bCI
:
if
bCI
:
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
(
resultFile
):
if
not
os
.
path
.
isfile
(
resultFile
):
break
break
...
@@ -202,16 +210,16 @@ if __name__ == "__main__":
...
@@ -202,16 +210,16 @@ if __name__ == "__main__":
runCmdStr
=
getRunProgCmdStr
(
dsType
,
resultFileType
,
dsFile
,
userresultFile
)
runCmdStr
=
getRunProgCmdStr
(
dsType
,
resultFileType
,
dsFile
,
userresultFile
)
promptInfo
=
"正在执行命令: {0}"
.
format
(
runCmdStr
)
promptInfo
=
"正在执行命令: {0}"
.
format
(
runCmdStr
)
#
outputPromptInfo(bCI, promptInfo, Color.white)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
white
)
if
bCI
==
False
:
if
bCI
==
False
:
promptInfo
=
"提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
promptInfo
=
"提示:如果验证程序长时间未结束,说明应用程序中可能存在死循环。请停止验证程序(Ctrl+c),修改应用程序后再验证。"
#
outputPromptInfo(bCI, promptInfo, Color.yellow)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
yellow
)
execResult
=
os
.
system
(
runCmdStr
)
execResult
=
os
.
system
(
runCmdStr
)
if
execResult
!=
0
:
if
execResult
!=
0
:
errorInfo
=
"应用程序执行异常,返回值:{0}。"
.
format
(
execResult
)
errorInfo
=
"应用程序执行异常,返回值:{0}。"
.
format
(
execResult
)
#
outputPromptInfo(bCI, errorInfo, Color.red)
outputPromptInfo
(
bCI
,
errorInfo
,
Color
.
red
)
exit
(
1
)
exit
(
1
)
if
os
.
path
.
isfile
(
resultFile
)
and
os
.
path
.
isfile
(
userresultFile
):
if
os
.
path
.
isfile
(
resultFile
)
and
os
.
path
.
isfile
(
userresultFile
):
...
@@ -221,13 +229,16 @@ if __name__ == "__main__":
...
@@ -221,13 +229,16 @@ 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"
#
outputPromptInfo(bCI, promptInfo, Color.red)
outputPromptInfo
(
bCI
,
promptInfo
,
Color
.
red
)
else
:
else
:
print
(
"选择 View 菜单中的 Explorer 打开文件列表,右键点击 writefile*.dat文件或user_writefile*.dat文件,在弹出的菜单中选择 Open With...,再选择 Hex Editor "
)
print
(
"选择 View 菜单中的 Explorer 打开文件列表,右键点击 writefile*.dat文件或user_writefile*.dat文件,在弹出的菜单中选择 Open With...,再选择 Hex Editor "
)
exit
(
1
)
exit
(
1
)
...
...
编写
预览
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论