Mercurial > repos > public > sbplib_julia
comparison test/Grids/grid_test.jl @ 1531:9da4ab4fb85e bugfix/sbp_operators/stencil_return_type
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 11 Apr 2024 22:50:42 +0200 |
parents | 0cd6cf62af93 |
children | 43aaf710463e |
comparison
equal
deleted
inserted
replaced
1456:f13857f37b8f | 1531:9da4ab4fb85e |
---|---|
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.) |
61 # Multi-argument functions | 63 # Multi-argument functions |
62 f(x,y) = sin(x)*cos(y) | 64 f(x,y) = sin(x)*cos(y) |
63 @test eval_on(g, f) == map(x̄->f(x̄...), g) | 65 @test eval_on(g, f) == map(x̄->f(x̄...), g) |
64 end | 66 end |
65 | 67 |
68 @testset "componentview" begin | |
69 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
70 | |
71 @test componentview(v, 1, 1) isa AbstractArray | |
72 @test componentview(v, 1, :) isa AbstractArray | |
73 | |
74 A = @SMatrix[ | |
75 1 4 7; | |
76 2 5 8; | |
77 3 6 9; | |
78 ] | |
79 v = [A .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
80 @test componentview(v, 2:3, 1:2) isa AbstractArray | |
81 | |
82 # Correctness of the result is tested in ArrayComponentView | |
83 end | |
84 | |
85 @testset "ArrayComponentView" begin | |
86 v = [@SMatrix[1 3; 2 4] .+ 100*i .+ 10*j for i ∈ 1:3, j∈ 1:4] | |
87 | |
88 @testset "==" begin | |
89 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(v, (1,1)) | |
90 @test ArrayComponentView(v, (1,1)) == ArrayComponentView(copy(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 | |
117 end | |
118 | |
66 @testset "_ncomponents" begin | 119 @testset "_ncomponents" begin |
67 @test Grids._ncomponents(Int) == 1 | 120 @test Grids._ncomponents(Int) == 1 |
68 @test Grids._ncomponents(Float64) == 1 | 121 @test Grids._ncomponents(Float64) == 1 |
69 @test Grids._ncomponents(Rational) == 1 | 122 @test Grids._ncomponents(Rational) == 1 |
70 | 123 |