Skip to content

Commit 9ba598c

Browse files
committed
Add tests
1 parent 58434e8 commit 9ba598c

File tree

2 files changed

+37
-3
lines changed

2 files changed

+37
-3
lines changed

src/nhs_grid.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function initialize_grid!(neighborhood_search::GridNeighborhoodSearch, y::Abstra
215215
@boundscheck checkbounds(y, eachindex_y)
216216

217217
# Ignore the parallelization backend here. This cannot be parallelized.
218-
for point in axes(y, 2)
218+
for point in eachindex_y
219219
# Get cell index of the point's cell
220220
point_coords = @inbounds extract_svector(y, Val(ndims(neighborhood_search)), point)
221221
cell = cell_coords(point_coords, neighborhood_search)
@@ -267,7 +267,11 @@ function update!(neighborhood_search::GridNeighborhoodSearch,
267267
end
268268

269269
# Update only with neighbor coordinates
270-
function update_grid!(neighborhood_search::GridNeighborhoodSearch, y::AbstractMatrix;
270+
function update_grid!(neighborhood_search::Union{GridNeighborhoodSearch{<:Any,
271+
SerialIncrementalUpdate},
272+
GridNeighborhoodSearch{<:Any,
273+
SemiParallelUpdate}},
274+
y::AbstractMatrix;
271275
parallelization_backend = default_backend(y),
272276
eachindex_y = axes(y, 2))
273277
(; cell_list, update_buffer) = neighborhood_search

test/nhs_grid.jl

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
@test neighbors5 == [36, 37, 38, 43, 44, 45]
146146
end
147147

148-
@testset "Rectangular Point Cloud 3D" begin
148+
@testset verbose=true "Rectangular Point Cloud 3D" begin
149149
#### Setup
150150
# Rectangle of equidistantly spaced points
151151
# from (x, y, z) = (-0.25, -0.25, -0.25) to (x, y, z) = (0.35, 0.35, 0.35).
@@ -188,6 +188,36 @@
188188
@test neighbors3 ==
189189
[115, 116, 117, 122, 123, 124, 129, 130, 131, 164, 165, 166, 171, 172,
190190
173, 178, 179, 180, 213, 214, 215, 220, 221, 222, 227, 228, 229]
191+
192+
update_strategies = (SerialUpdate(), ParallelUpdate())
193+
@testset verbose=true "eachindex_y $update_strategy" for update_strategy in
194+
update_strategies
195+
# Test that `eachindex_y` is passed correctly to the neighborhood search.
196+
# This requires `SerialUpdate` or `ParallelUpdate`.
197+
min_corner = min.(minimum(coordinates1, dims = 2),
198+
minimum(coordinates2, dims = 2))
199+
max_corner = max.(maximum(coordinates1, dims = 2),
200+
maximum(coordinates2, dims = 2))
201+
cell_list = FullGridCellList(; min_corner, max_corner, search_radius)
202+
nhs2 = GridNeighborhoodSearch{3}(; search_radius, n_points, update_strategy,
203+
cell_list)
204+
205+
# Initialize with all points
206+
initialize!(nhs2, coordinates1, coordinates1)
207+
208+
# Update with a subset of points
209+
update!(nhs2, coordinates2, coordinates2; eachindex_y = 120:220)
210+
211+
neighbors2 = sort(collect(PointNeighbors.eachneighbor(point_position1, nhs2)))
212+
neighbors3 = sort(collect(PointNeighbors.eachneighbor(point_position2, nhs2)))
213+
214+
# Check that the neighbors are the intersection of the previous neighbors
215+
# with the `eachindex_y` range.
216+
@test neighbors2 == Int[]
217+
@test neighbors3 ==
218+
[122, 123, 124, 129, 130, 131, 164, 165, 166, 171, 172, 173,
219+
178, 179, 180, 213, 214, 215, 220]
220+
end
191221
end
192222

193223
@testset verbose=true "Periodicity" begin

0 commit comments

Comments
 (0)