Mercurial > repos > public > sbplib_julia
changeset 1824:7a2375080287 refactor/grids/iterable_boundary_indices
WIP
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Wed, 19 Jun 2024 11:16:42 +0200 |
parents | 888e4092e2ed |
children | 98ae79eb0709 |
files | test/Grids/equidistant_grid_test.jl test/Grids/tensor_grid_test.jl |
diffstat | 2 files changed, 25 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/test/Grids/equidistant_grid_test.jl Tue Jun 11 21:43:01 2024 +0200 +++ b/test/Grids/equidistant_grid_test.jl Wed Jun 19 11:16:42 2024 +0200 @@ -70,12 +70,17 @@ @testset "boundary_indices" begin g = EquidistantGrid(0:0.1:1) - @test boundary_indices(g, Lower()) == (1,) - @test boundary_indices(g, Upper()) == (11,) + @test collect(boundary_indices(g, Lower())) == [(1,)] + @test collect(boundary_indices(g, Upper())) == [(11,)] + + + gf = collect(1:length(g)) + @test gf[boundary_indices(g, Lower()] == gf[1] + @test gf[boundary_indices(g, Upper()] == gf[11] g = EquidistantGrid(2:0.1:10) - @test boundary_indices(g, Lower()) == (1,) - @test boundary_indices(g, Upper()) == (81,) + @test collect(boundary_indices(g, Lower())) == [(1,)] + @test collect(boundary_indices(g, Upper())) == [(81,)] end
--- a/test/Grids/tensor_grid_test.jl Tue Jun 11 21:43:01 2024 +0200 +++ b/test/Grids/tensor_grid_test.jl Wed Jun 19 11:16:42 2024 +0200 @@ -175,14 +175,22 @@ g₂ = EquidistantGrid(range(2,3,length=6)) g₄ = ZeroDimGrid(@SVector[1,2]) - @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}()) == (1,:) - @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}()) == (11,:) - @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Lower}()) == (:,1) - @test boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Upper}()) == (:,6) - @test boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Lower}()) == (1,) - @test boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Upper}()) == (11,) - @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Lower}()) == (1,) - @test boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Upper}()) == (11,) + @test iterate(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}())) + + gf = reshape(1:(11*6),11,6) + @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}()))] == gf[1,:] + @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}()))] == gf[11,:] + @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Lower}()))] == gf[:,1] + @test gf[boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Upper}()))] == gf[:,6] + + @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Lower}())) == [(1,i) for i ∈ 1:6] + @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{1, Upper}())) == [(11,i) for i ∈ 1:6] + @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Lower}())) == [(i,1) for i ∈ 1:11] + @test collect(boundary_indices(TensorGrid(g₁, g₂), TensorGridBoundary{2, Upper}())) == [(i,6) for i ∈ 1:11] + @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Lower}())) == [(1,)] + @test collect(boundary_indices(TensorGrid(g₁, g₄), TensorGridBoundary{1, Upper}())) == [(11,)] + @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Lower}())) == [(1,)] + @test collect(boundary_indices(TensorGrid(g₄,g₁), TensorGridBoundary{2, Upper}())) == [(11,)] end end