Mercurial > repos > public > sbplib_julia
comparison test/Grids/grid_test.jl @ 1526:4df668d00d03 feature/grids/curvilinear
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 09 Apr 2024 07:58:27 +0200 |
parents | 0cd6cf62af93 |
children | 43aaf710463e |
comparison
equal
deleted
inserted
replaced
1506:535f32316637 | 1526:4df668d00d03 |
---|---|
13 | 13 |
14 @test coordinate_size(DummyGrid{Int, 1}()) == 1 | 14 @test coordinate_size(DummyGrid{Int, 1}()) == 1 |
15 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3 | 15 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}()) == 3 |
16 | 16 |
17 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3 | 17 @test coordinate_size(DummyGrid{SVector{3,Float64}, 2}) == 3 |
18 end | |
18 | 19 |
19 @testset "component_type" begin | 20 @testset "component_type" begin |
20 @test component_type(DummyGrid{Int,1}()) == Int | 21 @test component_type(DummyGrid{Int,1}()) == Int |
21 @test component_type(DummyGrid{Float64,1}()) == Float64 | 22 @test component_type(DummyGrid{Float64,1}()) == Float64 |
22 @test component_type(DummyGrid{Rational,1}()) == Rational | 23 @test component_type(DummyGrid{Rational,1}()) == Rational |
23 | 24 |
24 @test component_type(DummyGrid{SVector{3,Int},2}()) == Int | 25 @test component_type(DummyGrid{SVector{3,Int},2}()) == Int |
25 @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 | 26 @test component_type(DummyGrid{SVector{2,Float64},3}()) == Float64 |
26 @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational | 27 @test component_type(DummyGrid{SVector{4,Rational},4}()) == Rational |
27 | 28 |
28 @test component_type(DummyGrid{Float64,1}) == Float64 | 29 @test component_type(DummyGrid{Float64,1}) == Float64 |
29 @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 | 30 @test component_type(DummyGrid{SVector{2,Float64},3}) == Float64 |
30 end | 31 |
32 @test component_type(fill(@SVector[1,2], 4,2)) == Int | |
31 end | 33 end |
32 | 34 |
33 @testset "eval_on" begin | 35 @testset "eval_on" begin |
34 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) isa LazyArray | 36 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) isa LazyArray |
35 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) == fill(3.) | 37 @test eval_on(ZeroDimGrid(@SVector[1.,2.]), x̄->x̄[1]+x̄[2]) == fill(3.) |
64 end | 66 end |
65 | 67 |
66 @testset "componentview" begin | 68 @testset "componentview" begin |
67 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 69 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
68 | 70 |
69 @test componentview(v, 1, 1) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 71 @test componentview(v, 1, 1) isa AbstractArray |
70 @test componentview(v, 1, 2) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 72 @test componentview(v, 1, :) isa AbstractArray |
71 @test componentview(v, 2, 1) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
72 | |
73 @test componentview(v, 1, :) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
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 | 73 |
79 A = @SMatrix[ | 74 A = @SMatrix[ |
80 1 4 7; | 75 1 4 7; |
81 2 5 8; | 76 2 5 8; |
82 3 6 9; | 77 3 6 9; |
83 ] | 78 ] |
84 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 79 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] | 80 @test componentview(v, 2:3, 1:2) isa AbstractArray |
86 @test componentview(v, 2:3, 1:2) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 81 |
82 # Correctness of the result is tested in ArrayComponentView | |
87 end | 83 end |
88 | 84 |
89 @testset "ArrayComponentView" begin | 85 @testset "ArrayComponentView" begin |
90 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 86 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
91 | 87 |
92 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1)) | 88 @testset "==" begin |
93 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(v), (1,1)) | 89 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1)) |
94 @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | 90 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(v), (1,1)) |
95 @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1)) | 91 @test ArrayComponentView(v, (1,1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] |
92 @test [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] == ArrayComponentView(v, (1,1)) | |
93 end | |
94 | |
95 @testset "components" begin | |
96 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
97 | |
98 @test ArrayComponentView(v, (1, 1)) == [1 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
99 @test ArrayComponentView(v, (1, 2)) == [3 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
100 @test ArrayComponentView(v, (2, 1)) == [2 .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
101 | |
102 @test ArrayComponentView(v, (1, :)) == [@SVector[1,3] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
103 @test ArrayComponentView(v, (2, :)) == [@SVector[2,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
104 @test ArrayComponentView(v, (:, 1)) == [@SVector[1,2] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
105 @test ArrayComponentView(v, (:, 2)) == [@SVector[3,4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
106 | |
107 | |
108 A = @SMatrix[ | |
109 1 4 7; | |
110 2 5 8; | |
111 3 6 9; | |
112 ] | |
113 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
114 @test ArrayComponentView(v, (1:2, 1:2)) == [@SMatrix[1 4;2 5] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
115 @test ArrayComponentView(v, (2:3, 1:2)) == [@SMatrix[2 5;3 6] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
116 end | |
96 end | 117 end |
97 | 118 |
98 @testset "_ncomponents" begin | 119 @testset "_ncomponents" begin |
99 @test Grids._ncomponents(Int) == 1 | 120 @test Grids._ncomponents(Int) == 1 |
100 @test Grids._ncomponents(Float64) == 1 | 121 @test Grids._ncomponents(Float64) == 1 |