Skip to content

Commit 659646c

Browse files
committed
test/rtree: subtract!() for n-elements
1 parent da07ec8 commit 659646c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

test/rtree.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,38 @@ end
311311
@test SI.id(first(tree)) == 0
312312
end
313313
end
314+
315+
@testset "subtract!() removing n<=N central nodes" begin
316+
Random.seed!(32123)
317+
pts = [ntuple(_ -> 2rand()-1, 3) for _ in 1:200]
318+
# the test implies that all pts have different distances to the origin
319+
sort!(pts, by = pt -> maximum(abs, pt))
320+
reftree = RTree{Float64, 3}(Int, String, leaf_capacity = 5, branch_capacity = 5)
321+
SI.load!(reftree, enumerate(pts),
322+
convertel = x -> eltype(reftree)(SI.Rect(x[2], x[2]), x[1], string(x[1])))
323+
corembr = SI.Rect((0.0, 0.0, 0.0), (0.0, 0.0, 0.0))
324+
tree1 = deepcopy(reftree)
325+
@test length(tree1) == length(reftree)
326+
@testset "removing $n points" for (n, pt) in enumerate(pts)
327+
corembr = SI.combine(corembr, SI.Rect(pt, pt))
328+
329+
# subtracting centrermbr from tree1 removes just 1 point
330+
@test length(tree1) == length(reftree) - n + 1
331+
tree1_to_remove = collect(contained_in(tree1, corembr))
332+
@test length(tree1_to_remove) == 1
333+
@test SI.id(first(tree1_to_remove)) == n
334+
335+
SI.subtract!(tree1, corembr)
336+
@test length(tree1) == length(reftree) - n
337+
@test SI.check(tree1)
338+
339+
# subtracting centrermbr from tree2 removes n points
340+
tree2 = deepcopy(reftree)
341+
SI.subtract!(tree2, corembr)
342+
@test length(tree2) == length(reftree) - n
343+
@test SI.check(tree2)
344+
end
345+
end
314346
end
315347

316348
end

0 commit comments

Comments
 (0)