comparison test/Grids/equidistant_grid_test.jl @ 1529:43aaf710463e refactor/equidistant_grid/signature

Change to signature of equidistant_grid to same style as many array methods. See for example Array{T}(undef, dims...), zeros(T, dims...), fill(a, dims...) and more.
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 11 Apr 2024 22:31:04 +0200
parents 37cf9f79caa4
children c3425b4302b8 efe1fc4cb6b0
comparison
equal deleted inserted replaced
1528:d641798539c2 1529:43aaf710463e
103 end 103 end
104 end 104 end
105 105
106 106
107 @testset "equidistant_grid" begin 107 @testset "equidistant_grid" begin
108 @test equidistant_grid(4,0.0,1.0) isa EquidistantGrid 108 @test equidistant_grid(0.0,1.0, 4) isa EquidistantGrid
109 @test equidistant_grid((4,3),(0.0,0.0),(8.0,5.0)) isa TensorGrid 109 @test equidistant_grid((0.0,0.0),(8.0,5.0), 4, 3) isa TensorGrid
110 110
111 # constuctor 111 # constuctor
112 @test_throws DomainError equidistant_grid(0,0.0,1.0) 112 @test_throws DomainError equidistant_grid(0.0, 1.0, 0)
113 @test_throws DomainError equidistant_grid(1,1.0,1.0) 113 @test_throws DomainError equidistant_grid(1.0, 1.0, 1)
114 @test_throws DomainError equidistant_grid(1,1.0,-1.0) 114 @test_throws DomainError equidistant_grid(1.0, -1.0, 1)
115 115
116 @test_throws DomainError equidistant_grid((0,0),(0.0,0.0),(1.0,1.0)) 116 @test_throws DomainError equidistant_grid((0.0,0.0),(1.0,1.0), 0, 0)
117 @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(1.0,1.0)) 117 @test_throws DomainError equidistant_grid((1.0,1.0),(1.0,1.0), 1, 1)
118 @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(-1.0,-1.0)) 118 @test_throws DomainError equidistant_grid((1.0,1.0),(-1.0,-1.0), 1, 1)
119 119
120 @testset "Base" begin 120 @testset "Base" begin
121 @test eltype(equidistant_grid(4,0.0,1.0)) == Float64 121 @test eltype(equidistant_grid(0.0, 1.0, 4)) == Float64
122 @test eltype(equidistant_grid((4,3),(0,0),(1,3))) <: AbstractVector{Float64} 122 @test eltype(equidistant_grid((0,0),(1,3), 4, 3)) <: AbstractVector{Float64}
123 123
124 @test size(equidistant_grid(4,0.0,1.0)) == (4,) 124 @test size(equidistant_grid(0.0, 1.0, 4)) == (4,)
125 @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) 125 @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == (5,3)
126 126
127 @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),1) == 5 127 @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 1) == 5
128 @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),2) == 3 128 @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 2) == 3
129 129
130 @test ndims(equidistant_grid(4,0.0,1.0)) == 1 130 @test ndims(equidistant_grid(0.0, 1.0, 4)) == 1
131 @test ndims(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == 2 131 @test ndims(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == 2
132 end 132 end
133 133
134 @testset "getindex" begin 134 @testset "getindex" begin
135 g = equidistant_grid((5,3), (-1.0,0.0), (0.0,7.11)) 135 g = equidistant_grid((-1.0,0.0), (0.0,7.11), 5, 3)
136 gp = collect(g); 136 gp = collect(g);
137 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); 137 p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11);
138 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11); 138 (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11);
139 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11); 139 (-0.5,0.) (-0.5,7.11/2) (-0.5,7.11);
140 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11); 140 (-0.25,0.) (-0.25,7.11/2) (-0.25,7.11);