comparison test/Grids/tensor_grid_test.jl @ 1349:42ecd4b3e215 refactor/grids

Add support for cartesian indices on TensorGrid
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 19 May 2023 14:53:49 +0200
parents 279179677040
children 3d6425c36d32
comparison
equal deleted inserted replaced
1348:279179677040 1349:42ecd4b3e215
32 @test TensorGrid(g₁, g₄)[3] isa SVector{3,Float64} 32 @test TensorGrid(g₁, g₄)[3] isa SVector{3,Float64}
33 @test TensorGrid(g₁, g₄)[3] == [0.2, 1., 2.] 33 @test TensorGrid(g₁, g₄)[3] == [0.2, 1., 2.]
34 34
35 @test TensorGrid(g₁, g₄, g₂)[3,2] isa SVector{4,Float64} 35 @test TensorGrid(g₁, g₄, g₂)[3,2] isa SVector{4,Float64}
36 @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
38
39 @testset "cartesian indexing" begin
40 cases = [
41 (TensorGrid(g₁, g₂), (1,1) ),
42 (TensorGrid(g₁, g₂), (3,5) ),
43 (TensorGrid(g₁, g₂), (10,6) ),
44 (TensorGrid(g₁, g₃), (1,1) ),
45 (TensorGrid(g₁, g₂, g₃), (3,4,5)),
46 (TensorGrid(g₁, g₄), (3) ),
47 (TensorGrid(g₁, g₄, g₂), (3,2) ),
48 ]
49
50 @testset "i = $is" for (g, is) ∈ cases
51 @test g[CartesianIndex(is...)] == g[is...]
52 end
37 end 53 end
38 54
39 @testset "eachindex" begin 55 @testset "eachindex" begin
40 @test eachindex(TensorGrid(g₁, g₂)) == CartesianIndices((11,6)) 56 @test eachindex(TensorGrid(g₁, g₂)) == CartesianIndices((11,6))
41 @test eachindex(TensorGrid(g₁, g₃)) == CartesianIndices((11,10)) 57 @test eachindex(TensorGrid(g₁, g₃)) == CartesianIndices((11,10))