Skip to content

Commit

Permalink
test: ✅ 整理测试集,将非必要的性能评估移至别处
Browse files Browse the repository at this point in the history
  • Loading branch information
ARCJ137442 committed Aug 25, 2023
1 parent e18d662 commit 2d104c5
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 109 deletions.
4 changes: 1 addition & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ version = "2.2.0"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[extras]
Profile = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"
ProfileView = "c46f51b8-102a-5cf2-8d2c-8597cb0e0da7"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Profile", "ProfileView"]
test = ["Test"]
91 changes: 91 additions & 0 deletions test/commons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,94 @@ if !isdefined(Main, :Test)

"测试集:\n$test_set" |> println
end

begin "用于「判等失败」后递归查找「不等の元素」的断言函数"

"兜底断言"
recursive_assert(t1::Any, t2::Any) = @assert t1 == t2

"通用复合词项"
recursive_assert(t1::CommonCompound, t2::CommonCompound) = begin
@assert typeof(t1) == typeof(t2)
# 【20230820 12:52:34】因为复合词项现采用「预先排序」的方式,现在只需逐个比对
@assert length(t1) == length(t2)
for (tt1, tt2) in zip(t1.terms, t2.terms)
@assert tt1 == tt2 "$tt1$tt2 !"
end
end

"陈述"
recursive_assert(s1::Statement, s2::Statement) = begin
recursive_assert(s1.ϕ1, s2.ϕ1)
recursive_assert(s1.ϕ2, s2.ϕ2)
end

end

"通用测试の宏"
macro equal_test(
parser::Union{Symbol,Expr},
test_set::Union{Symbol,Expr},
)
# quote里的`($parser)`已经自动把内部对象eval了
quote
try
# 词项 #
# 二次转换
local converted_terms = ($parser).(($test_set).terms)
@info "converted_terms@$($parser):"
join(converted_terms, "\n") |> println
local reconverted_terms = ($parser).(converted_terms)
@info "reconverted_terms@$($parser):"
join(reconverted_terms, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_terms, ($test_set).terms) # 📝Julia: @simd的循环变量必须是单个标识符,且zip无法参与循环
if reconv origin
@error "$($parser): Not eq!" reconv origin
# if typeof(reconv) == typeof(origin) <: Statement
recursive_assert(reconv, origin)
end
@test reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
# 语句 #
# 二次转换
local converted_sentences = ($parser).(($test_set).sentences)
@info "converted_sentences@$($parser):"
join(converted_sentences, "\n") |> println
local reconverted_sentences = ($parser).(converted_sentences)
@info "converted_sentences@$($parser):"
join(converted_sentences, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_sentences, ($test_set).sentences)
if reconv origin
@error "$($parser): Not eq!" reconv origin
dump.([reconv, origin]; maxdepth=typemax(Int))
end
@assert reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
# 任务 #
# 二次转换
local converted_tasks = ($parser).(($test_set).tasks)
@info "converted_tasks@$($parser):"
join(converted_tasks, "\n") |> println
local reconverted_tasks = ($parser).(converted_tasks)
@info "converted_tasks@$($parser):"
join(converted_tasks, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_tasks, ($test_set).tasks)
if reconv origin
@error "$($parser): Not eq!" reconv origin
dump.([reconv, origin]; maxdepth=typemax(Int))
end
@assert reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
catch e # 打印堆栈
Base.printstyled("ERROR: "; color=:red, bold=true)
Base.showerror(stdout, e)
Base.show_backtrace(stdout, Base.catch_backtrace())
rethrow(e)
end
end |> esc # 在调用的上下文中解析
end

@info "共用测试环境搭建完成!"
17 changes: 16 additions & 1 deletion test/preftest.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
isdefined(Main, :JuNarsese) || include("commons.jl") # 已在此中导入JuNarsese、Test
#=
专注于JuNarsese的性能测试
专注于JuNarsese的性能评估
=#

# 使用可视化的性能评估库`ProfileView`
using ProfileView # 参考:https://www.math.pku.edu.cn/teachers/lidf/docs/Julia/html/_book/perf.html#perf-prof

begin "番外:性能评估"

@info "性能评估开始"

# 避免与VSCode冲突
ProfileView.@profview @equal_test StringParser_ascii test_set # 先前测试已触发编译

readline() # 在直接执行时,防止异步操作提前退出(不会影响`Pkg.test`)

end
105 changes: 1 addition & 104 deletions test/test_conversion.jl
Original file line number Diff line number Diff line change
@@ -1,93 +1,4 @@
include("commons.jl") # 已在此中导入JuNarsese、Test

begin "用于「判等失败」后递归查找「不等の元素」的断言函数"

"兜底断言"
recursive_assert(t1::Any, t2::Any) = @assert t1 == t2

"通用复合词项"
recursive_assert(t1::CommonCompound, t2::CommonCompound) = begin
@assert typeof(t1) == typeof(t2)
# 【20230820 12:52:34】因为复合词项现采用「预先排序」的方式,现在只需逐个比对
@assert length(t1) == length(t2)
for (tt1, tt2) in zip(t1.terms, t2.terms)
@assert tt1 == tt2 "$tt1$tt2 !"
end
end

"陈述"
recursive_assert(s1::Statement, s2::Statement) = begin
recursive_assert(s1.ϕ1, s2.ϕ1)
recursive_assert(s1.ϕ2, s2.ϕ2)
end

end

"通用测试の宏"
macro equal_test(
parser::Union{Symbol,Expr},
test_set::Union{Symbol,Expr},
)
# quote里的`($parser)`已经自动把内部对象eval了
quote
try
# 词项 #
# 二次转换
local converted_terms = ($parser).(($test_set).terms)
@info "converted_terms@$($parser):"
join(converted_terms, "\n") |> println
local reconverted_terms = ($parser).(converted_terms)
@info "reconverted_terms@$($parser):"
join(reconverted_terms, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_terms, ($test_set).terms) # 📝Julia: @simd的循环变量必须是单个标识符,且zip无法参与循环
if reconv origin
@error "$($parser): Not eq!" reconv origin
# if typeof(reconv) == typeof(origin) <: Statement
recursive_assert(reconv, origin)
end
@test reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
# 语句 #
# 二次转换
local converted_sentences = ($parser).(($test_set).sentences)
@info "converted_sentences@$($parser):"
join(converted_sentences, "\n") |> println
local reconverted_sentences = ($parser).(converted_sentences)
@info "converted_sentences@$($parser):"
join(converted_sentences, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_sentences, ($test_set).sentences)
if reconv origin
@error "$($parser): Not eq!" reconv origin
dump.([reconv, origin]; maxdepth=typemax(Int))
end
@assert reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
# 任务 #
# 二次转换
local converted_tasks = ($parser).(($test_set).tasks)
@info "converted_tasks@$($parser):"
join(converted_tasks, "\n") |> println
local reconverted_tasks = ($parser).(converted_tasks)
@info "converted_tasks@$($parser):"
join(converted_tasks, "\n") |> println
# 比对相等
for (reconv, origin) in zip(reconverted_tasks, ($test_set).tasks)
if reconv origin
@error "$($parser): Not eq!" reconv origin
dump.([reconv, origin]; maxdepth=typemax(Int))
end
@assert reconv == origin # 📌【20230806 15:24:11】此处引入额外参数会报错……引用上下文复杂
end
catch e # 打印堆栈
Base.printstyled("ERROR: "; color=:red, bold=true)
Base.showerror(stdout, e)
Base.show_backtrace(stdout, Base.catch_backtrace())
rethrow(e)
end
end |> esc # 在调用的上下文中解析
end
isdefined(Main, :JuNarsese) || include("commons.jl") # 已在此中导入JuNarsese、Test

begin "报错debug专用"
# 测试@原生对象
Expand Down Expand Up @@ -134,17 +45,3 @@ end
@equal_test NativeParser_vector test_set
end
end

# 使用可视化的性能评估库`ProfileView`
using ProfileView # 参考:https://www.math.pku.edu.cn/teachers/lidf/docs/Julia/html/_book/perf.html#perf-prof

begin "番外:性能评估"

@info "性能评估开始"

# 避免与VSCode冲突
ProfileView.@profview @equal_test StringParser_ascii test_set # 先前测试已触发编译

readline() # 在直接执行时,防止异步操作提前退出(不会影响`Pkg.test`)

end
2 changes: 1 addition & 1 deletion test/test_narsese.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
include("commons.jl") # 已在此中导入JuNarsese、Test
isdefined(Main, :JuNarsese) || include("commons.jl") # 已在此中导入JuNarsese、Test

A,B,C,D,E = "A B C D E" |> split .|> String .|> Symbol .|> Word
@assert (((AB, BC, CD), (AB, BC, CD))) == (((AB, BC, CD), (AB, BC, CD)))
Expand Down

0 comments on commit 2d104c5

Please sign in to comment.