Mercurial > repos > public > sbplib_julia
diff test/Grids/curvilinear_grid_test.jl @ 1450:647c8b18b84f feature/grids/curvilinear
Implement iterator interface
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Nov 2023 10:16:19 +0100 |
parents | af73340a8f0e |
children | 2e08f3444354 |
line wrap: on
line diff
--- a/test/Grids/curvilinear_grid_test.jl Thu Nov 23 10:14:48 2023 +0100 +++ b/test/Grids/curvilinear_grid_test.jl Thu Nov 23 10:16:19 2023 +0100 @@ -62,16 +62,43 @@ # TODO: Test with different types of logical grids @testset "Iterator interface" begin - # @test eltype(EquidistantGrid(0:10)) == Int - # @test eltype(EquidistantGrid(0:2:10)) == Int - # @test eltype(EquidistantGrid(0:0.1:10)) == Float64 + sg = CurvilinearGrid( + equidistant_grid((15,11), (0,0), (1,1)), + map(ξ̄ -> @SArray[ξ̄[1], ξ̄[2], -ξ̄[1]], lg), rand(SMatrix{2,3,Float64},15,11) + ) + + @test eltype(cg) == SVector{2,Float64} + @test eltype(sg) == SVector{3,Float64} + + @test eltype(typeof(cg)) == SVector{2,Float64} + @test eltype(typeof(sg)) == SVector{3,Float64} + + @test size(cg) == (11,11) + @test size(sg) == (15,11) + + @test size(cg,2) == 11 + @test size(sg,2) == 11 - # @test size(EquidistantGrid(0:10)) == (11,) - # @test size(EquidistantGrid(0:0.1:10)) == (101,) + @test length(cg) == 121 + @test length(sg) == 165 + + @test Base.IteratorSize(cg) == Base.HasShape{2}() + @test Base.IteratorSize(typeof(cg)) == Base.HasShape{2}() + + @test Base.IteratorSize(sg) == Base.HasShape{2}() + @test Base.IteratorSize(typeof(sg)) == Base.HasShape{2}() - # @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5] + element, state = iterate(cg) + @test element == lg[1,1].*2 + element, _ = iterate(cg, state) + @test element == lg[2,1].*2 - # @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}() + element, state = iterate(sg) + @test element == sg.physicalcoordinates[1,1] + element, _ = iterate(sg, state) + @test element == sg.physicalcoordinates[2,1] + + @test collect(cg) == 2 .* lg end @testset "Base" begin