comparison test/Grids/tensor_grid_test.jl @ 1348:279179677040 refactor/grids

Add testsets under "Indexing interface" for tensor grids
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 19 May 2023 14:31:16 +0200
parents dbddd0f61bde
children 42ecd4b3e215
comparison
equal deleted inserted replaced
1347:08f06bfacd5c 1348:279179677040
15 @test TensorGrid(g₁, g₂, g₃) isa Grid{SVector{3,Float64}, 3} 15 @test TensorGrid(g₁, g₂, g₃) isa Grid{SVector{3,Float64}, 3}
16 @test TensorGrid(g₁, g₄) isa Grid{SVector{3,Float64}, 1} 16 @test TensorGrid(g₁, g₄) isa Grid{SVector{3,Float64}, 1}
17 @test TensorGrid(g₁, g₄, g₂) isa Grid{SVector{4,Float64}, 2} 17 @test TensorGrid(g₁, g₄, g₂) isa Grid{SVector{4,Float64}, 2}
18 18
19 @testset "Indexing Interface" begin 19 @testset "Indexing Interface" begin
20 @test TensorGrid(g₁, g₂)[1,1] isa SVector{2,Float64} 20 @testset "regular indexing" begin
21 @test TensorGrid(g₁, g₂)[1,1] == [0.0,2.0] 21 @test TensorGrid(g₁, g₂)[1,1] isa SVector{2,Float64}
22 @test TensorGrid(g₁, g₂)[3,5] == [0.2,2.8] 22 @test TensorGrid(g₁, g₂)[1,1] == [0.0,2.0]
23 @test TensorGrid(g₁, g₂)[10,6] == [0.9,3.0] 23 @test TensorGrid(g₁, g₂)[3,5] == [0.2,2.8]
24 @test TensorGrid(g₁, g₂)[10,6] == [0.9,3.0]
24 25
25 @test TensorGrid(g₁, g₃)[1,1] isa SVector{2,Float64} 26 @test TensorGrid(g₁, g₃)[1,1] isa SVector{2,Float64}
26 @test TensorGrid(g₁, g₃)[1,1] == [0.0,1.0] 27 @test TensorGrid(g₁, g₃)[1,1] == [0.0,1.0]
27 28
28 @test TensorGrid(g₁, g₂, g₃)[3,4,5] isa SVector{3,Float64} 29 @test TensorGrid(g₁, g₂, g₃)[3,4,5] isa SVector{3,Float64}
29 @test TensorGrid(g₁, g₂, g₃)[3,4,5] == [0.2, 2.6, 5.0] 30 @test TensorGrid(g₁, g₂, g₃)[3,4,5] == [0.2, 2.6, 5.0]
30 31
31 @test TensorGrid(g₁, g₄)[3] isa SVector{3,Float64} 32 @test TensorGrid(g₁, g₄)[3] isa SVector{3,Float64}
32 @test TensorGrid(g₁, g₄)[3] == [0.2, 1., 2.] 33 @test TensorGrid(g₁, g₄)[3] == [0.2, 1., 2.]
33 34
34 @test TensorGrid(g₁, g₄, g₂)[3,2] isa SVector{4,Float64} 35 @test TensorGrid(g₁, g₄, g₂)[3,2] isa SVector{4,Float64}
35 @test TensorGrid(g₁, g₄, g₂)[3,2] == [0.2, 1., 2., 2.2] 36 @test TensorGrid(g₁, g₄, g₂)[3,2] == [0.2, 1., 2., 2.2]
37 end
36 38
37 @test eachindex(TensorGrid(g₁, g₂)) == CartesianIndices((11,6)) 39 @testset "eachindex" begin
38 @test eachindex(TensorGrid(g₁, g₃)) == CartesianIndices((11,10)) 40 @test eachindex(TensorGrid(g₁, g₂)) == CartesianIndices((11,6))
39 @test eachindex(TensorGrid(g₁, g₂, g₃)) == CartesianIndices((11,6,10)) 41 @test eachindex(TensorGrid(g₁, g₃)) == CartesianIndices((11,10))
40 @test eachindex(TensorGrid(g₁, g₄)) == CartesianIndices((11,)) 42 @test eachindex(TensorGrid(g₁, g₂, g₃)) == CartesianIndices((11,6,10))
41 @test eachindex(TensorGrid(g₁, g₄, g₂)) == CartesianIndices((11,6)) 43 @test eachindex(TensorGrid(g₁, g₄)) == CartesianIndices((11,))
44 @test eachindex(TensorGrid(g₁, g₄, g₂)) == CartesianIndices((11,6))
45 end
42 end 46 end
43 47
44 @testset "Iterator interface" begin 48 @testset "Iterator interface" begin
45 @test eltype(TensorGrid(g₁, g₂)) == SVector{2,Float64} 49 @test eltype(TensorGrid(g₁, g₂)) == SVector{2,Float64}
46 @test eltype(TensorGrid(g₁, g₃)) == SVector{2,Float64} 50 @test eltype(TensorGrid(g₁, g₃)) == SVector{2,Float64}