Mercurial > repos > public > sbplib_julia
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1475:76b190ca9a27 | 1476:62f9d0387a2a |
|---|---|
| 68 | 68 |
| 69 @test componentview(v, 1, 1) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 69 @test componentview(v, 1, 1) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
| 70 @test componentview(v, 1, 2) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 70 @test componentview(v, 1, 2) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
| 71 @test componentview(v, 2, 1) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 71 @test componentview(v, 2, 1) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
| 72 | 72 |
| 73 # should work with colon | 73 @test componentview(v, 1, :) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
| 74 # should return a view which can be index like the grid function | 74 @test componentview(v, 2, :) == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
| 75 @test componentview(v, :, 1) == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 76 @test componentview(v, :, 2) == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 77 | |
| 78 | |
| 79 A = @SMatrix[ | |
| 80 1 4 7; | |
| 81 2 5 8; | |
| 82 3 6 9; | |
| 83 ] | |
| 84 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 85 @test componentview(v, 1:2, 1:2) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 86 @test componentview(v, 2:3, 1:2) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 87 end | |
| 88 | |
| 89 @testset "ArrayComponentView" begin | |
| 90 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 91 | |
| 92 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1)) | |
| 93 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(v), (1,1)) | |
| 94 @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
| 95 @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1)) | |
| 75 end | 96 end |
| 76 | 97 |
| 77 @testset "_ncomponents" begin | 98 @testset "_ncomponents" begin |
| 78 @test Grids._ncomponents(Int) == 1 | 99 @test Grids._ncomponents(Int) == 1 |
| 79 @test Grids._ncomponents(Float64) == 1 | 100 @test Grids._ncomponents(Float64) == 1 |
