From 76f4ad8b047d08baa809a3f0dffe81db1a1ecf40 Mon Sep 17 00:00:00 2001 From: guo-yong-zhi Date: Tue, 21 Dec 2021 11:17:06 +0800 Subject: [PATCH] fix test --- src/Stuffing.jl | 8 ++++---- test/runtests.jl | 28 +++++++++++++++++----------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/src/Stuffing.jl b/src/Stuffing.jl index a589ff1..95fbf52 100644 --- a/src/Stuffing.jl +++ b/src/Stuffing.jl @@ -97,14 +97,14 @@ function packing(mask, objs, args...; background=:auto, maskbackground=:auto, ka end function packing!(qts, args...; kargs...) place!(qts) - ep, nc = fit!(qts, args...; kargs...) - @info "$ep epochs, $nc collections" - if nc != 0 + nepoch, ncollection = fit!(qts, args...; kargs...) + @info "$nepoch epochs, $ncollection collections" + if ncollection != 0 colllist = first.(batchcollisions(qts)) get_text(i) = i > 1 ? "obj_$(i - 1)" : "#MASK#" @warn "have $(length(colllist)) collisions:\n" * string([(get_text(i), get_text(j)) for (i, j) in colllist]) end - qts + nepoch, ncollection end end diff --git a/test/runtests.jl b/test/runtests.jl index 4d330e4..71f2d8e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -45,18 +45,24 @@ include("test_fit.jl") setshift!(qts[1], (-1000, -1000)) @test collision(qts[1], qts[2])[1] < 0 - mask = fill(true, 500, 800) # can be any AbstractMatrix - objs = [] - for i in 1:30 - s = 20 + randexp() * 50 - obj = fill(true, round(Int, s) + 1, round(Int, s * (0.5 + rand() / 2)) + 1) # Bool Matrix implied that background = false - push!(objs, obj) + ncollection = -1 + nepoch = 0 + while ncollection != 0 && nepoch < 10000 + mask = fill(true, 500, 800) # can be any AbstractMatrix + objs = [] + for i in 1:30 + s = 20 + randexp() * 50 + obj = fill(true, round(Int, s) + 1, round(Int, s * (0.5 + rand() / 2)) + 1) # Bool Matrix implied that background = false + push!(objs, obj) + end + sort!(objs, by=prod ∘ size, rev=true) + packing(mask, objs, 10) + qts = qtrees(objs, mask=mask); + setpositions!(qts, :, (200, 300)) + ep, nc = packing!(qts, trainer=Trainer.trainepoch_P2!) + nepoch += ep + ncollection = nc end - sort!(objs, by=prod ∘ size, rev=true) - packing(mask, objs, 10) - qts = qtrees(objs, mask=mask); - setpositions!(qts, :, (200, 300)) - packing!(qts, trainer=Trainer.trainepoch_P2!) getpositions(qts) @test isempty(outofkernelbounds(qts[1], qts[2:end])) @test isempty(outofbounds(qts[1], qts[2:end]))