Mercurial > repos > public > sbplib_julia
diff test/Grids/grid_test.jl @ 1476:62f9d0387a2a feature/grids/componentview
Introduce a view type and implement sliced indexing for the components.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 01 Dec 2023 14:58:05 +0100 |
parents | 276c38a48aac |
children | a7689021d4c2 |
line wrap: on
line diff
--- a/test/Grids/grid_test.jl Fri Dec 01 13:36:47 2023 +0100 +++ b/test/Grids/grid_test.jl Fri Dec 01 14:58:05 2023 +0100 @@ -70,8 +70,29 @@ @test componentview(v, 1, 2) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] @test componentview(v, 2, 1) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] - # should work with colon - # should return a view which can be index like the grid function + @test componentview(v, 1, :) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test componentview(v, 2, :) == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test componentview(v, :, 1) == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test componentview(v, :, 2) == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + + + A = @SMatrix[ + 1 4 7; + 2 5 8; + 3 6 9; + ] + v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test componentview(v, 1:2, 1:2) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test componentview(v, 2:3, 1:2) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] +end + +@testset "ArrayComponentView" begin + v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + + @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1)) + @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(v), (1,1)) + @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] + @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1)) end @testset "_ncomponents" begin