|
8 | 8 | vov = PointNeighbors.DynamicVectorOfVectors{ELTYPE}(max_outer_length = 20, |
9 | 9 | max_inner_length = 4) |
10 | 10 |
|
11 | | - # Test internal size |
12 | | - @test size(vov.backend) == (4, 20) |
13 | | - |
14 | 11 | function verify(vov, vov_ref) |
15 | 12 | @test length(vov) == length(vov_ref) |
16 | 13 | @test eachindex(vov) == eachindex(vov_ref) |
|
24 | 21 | end |
25 | 22 | end |
26 | 23 |
|
27 | | - # Initial check |
28 | | - verify(vov, vov_ref) |
| 24 | + @testset "Initial state" begin |
| 25 | + # Test internal size |
| 26 | + @test size(vov.backend) == (4, 20) |
| 27 | + |
| 28 | + # Initial check |
| 29 | + verify(vov, vov_ref) |
| 30 | + end |
| 31 | + |
| 32 | + @testset "First push!" begin |
| 33 | + push!(vov_ref, type.([1, 3, 2])) |
| 34 | + push!(vov, type.([1, 3, 2])) |
| 35 | + |
| 36 | + verify(vov, vov_ref) |
| 37 | + end |
| 38 | + |
| 39 | + @testset "push! multiple items" begin |
| 40 | + push!(vov_ref, type.([4]), type.([5, 6, 7, 8])) |
| 41 | + push!(vov, type.([4]), type.([5, 6, 7, 8])) |
| 42 | + |
| 43 | + verify(vov, vov_ref) |
| 44 | + end |
| 45 | + |
| 46 | + @testset "push! to an inner vector" begin |
| 47 | + push!(vov_ref[1], type(12)) |
| 48 | + PointNeighbors.pushat!(vov, 1, type(12)) |
29 | 49 |
|
30 | | - # First `push!` |
31 | | - push!(vov_ref, type.([1, 2, 3])) |
32 | | - push!(vov, type.([1, 2, 3])) |
| 50 | + verify(vov, vov_ref) |
| 51 | + end |
33 | 52 |
|
34 | | - verify(vov, vov_ref) |
| 53 | + @testset "push! overflow" begin |
| 54 | + error_ = ErrorException("cell list is full. Use a larger `max_points_per_cell`.") |
| 55 | + @test_throws error_ PointNeighbors.pushat!(vov, 1, type(13)) |
35 | 56 |
|
36 | | - # `push!` multiple items |
37 | | - push!(vov_ref, type.([4]), type.([5, 6, 7, 8])) |
38 | | - push!(vov, type.([4]), type.([5, 6, 7, 8])) |
| 57 | + verify(vov, vov_ref) |
| 58 | + end |
39 | 59 |
|
40 | | - verify(vov, vov_ref) |
| 60 | + @testset "deleteat!" begin |
| 61 | + # Delete entry of inner vector. Note that this changes the order of the elements. |
| 62 | + deleteat!(vov_ref[3], 2) |
| 63 | + PointNeighbors.deleteatat!(vov, 3, 2) |
41 | 64 |
|
42 | | - # `push!` to an inner vector |
43 | | - push!(vov_ref[1], type(12)) |
44 | | - PointNeighbors.pushat!(vov, 1, type(12)) |
| 65 | + @test vov_ref[3] == type.([5, 7, 8]) |
| 66 | + @test vov[3] == type.([5, 8, 7]) |
45 | 67 |
|
46 | | - # `push!` overflow |
47 | | - error_ = ErrorException("cell list is full. Use a larger `max_points_per_cell`.") |
48 | | - @test_throws error_ PointNeighbors.pushat!(vov, 1, type(13)) |
| 68 | + # Delete second to last entry |
| 69 | + deleteat!(vov_ref[3], 2) |
| 70 | + PointNeighbors.deleteatat!(vov, 3, 2) |
49 | 71 |
|
50 | | - verify(vov, vov_ref) |
| 72 | + @test vov_ref[3] == type.([5, 8]) |
| 73 | + @test vov[3] == type.([5, 7]) |
51 | 74 |
|
52 | | - # Delete entry of inner vector. Note that this changes the order of the elements. |
53 | | - deleteat!(vov_ref[3], 2) |
54 | | - PointNeighbors.deleteatat!(vov, 3, 2) |
| 75 | + # Delete last entry |
| 76 | + deleteat!(vov_ref[3], 2) |
| 77 | + PointNeighbors.deleteatat!(vov, 3, 2) |
55 | 78 |
|
56 | | - @test vov_ref[3] == type.([5, 7, 8]) |
57 | | - @test vov[3] == type.([5, 8, 7]) |
| 79 | + # Now they are identical again |
| 80 | + verify(vov, vov_ref) |
58 | 81 |
|
59 | | - # Delete second to last entry |
60 | | - deleteat!(vov_ref[3], 2) |
61 | | - PointNeighbors.deleteatat!(vov, 3, 2) |
| 82 | + # Delete the remaining entry of this vector |
| 83 | + deleteat!(vov_ref[3], 1) |
| 84 | + PointNeighbors.deleteatat!(vov, 3, 1) |
62 | 85 |
|
63 | | - @test vov_ref[3] == type.([5, 8]) |
64 | | - @test vov[3] == type.([5, 7]) |
| 86 | + verify(vov, vov_ref) |
| 87 | + end |
65 | 88 |
|
66 | | - # Delete last entry |
67 | | - deleteat!(vov_ref[3], 2) |
68 | | - PointNeighbors.deleteatat!(vov, 3, 2) |
| 89 | + # Skip for Tuples |
| 90 | + if ELTYPE <: Number |
| 91 | + @testset "sorteach!" begin |
| 92 | + # Make sure that the first inner vector is unsorted. |
| 93 | + # If this fails, make sure the tests above don't yield a sorted vector. |
| 94 | + @test vov[1] != sort(vov[1]) |
69 | 95 |
|
70 | | - # Now they are identical again |
71 | | - verify(vov, vov_ref) |
| 96 | + PointNeighbors.sorteach!(vov) |
| 97 | + PointNeighbors.sorteach!(vov_ref) |
72 | 98 |
|
73 | | - # Delete the remaining entry of this vector |
74 | | - deleteat!(vov_ref[3], 1) |
75 | | - PointNeighbors.deleteatat!(vov, 3, 1) |
| 99 | + @test vov[1] == sort(vov[1]) |
76 | 100 |
|
77 | | - verify(vov, vov_ref) |
| 101 | + verify(vov, vov_ref) |
| 102 | + end |
| 103 | + end |
78 | 104 |
|
79 | | - # `empty!` |
80 | | - empty!(vov_ref) |
81 | | - empty!(vov) |
| 105 | + @testset "empty!" begin |
| 106 | + empty!(vov_ref) |
| 107 | + empty!(vov) |
82 | 108 |
|
83 | | - verify(vov, vov_ref) |
| 109 | + verify(vov, vov_ref) |
| 110 | + end |
84 | 111 | end |
85 | 112 | end |
0 commit comments