Mercurial > repos > public > sbplib_julia
diff test/Grids/equidistant_grid_test.jl @ 1259:ee57bdb366e4 refactor/grids
Reorganize some EquidistantGrid tests and add test for IteratorSize and eachindex
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 23 Feb 2023 12:22:00 +0100 |
parents | 1989d432731a |
children | a4834779cd6d |
line wrap: on
line diff
--- a/test/Grids/equidistant_grid_test.jl Thu Feb 23 11:40:25 2023 +0100 +++ b/test/Grids/equidistant_grid_test.jl Thu Feb 23 12:22:00 2023 +0100 @@ -9,12 +9,31 @@ @test EquidistantGrid(range(0,1,length=10)) isa EquidistantGrid @test EquidistantGrid(LinRange(0,1,11)) isa EquidistantGrid - @testset "Base" begin + @testset "Indexing Interface" begin + g = EquidistantGrid(0:0.1:10) + @test g[1] == 0.0 + @test g[5] == 0.4 + @test g[101] == 10.0 + + @test g[begin] == 0.0 + @test g[end] == 10.0 + + @test all(eachindex(g) .== 1:101) + end + + @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 @test size(EquidistantGrid(0:10)) == (11,) @test size(EquidistantGrid(0:0.1:10)) == (101,) + + @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5] + + @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}() + end + + @testset "Base" begin @test ndims(EquidistantGrid(0:10)) == 1 end @@ -28,21 +47,6 @@ @test inverse_spacing(EquidistantGrid(0:0.1:10)) == 10 end - @testset "collect" begin - g = EquidistantGrid(0:0.1:0.5) - @test collect(g) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5] - end - - @testset "getindex" begin - g = EquidistantGrid(0:0.1:10) - @test g[1] == 0.0 - @test g[5] == 0.4 - @test g[101] == 10.0 - - @test g[begin] == 0.0 - @test g[end] == 10.0 - end - @testset "boundary_identifiers" begin g = EquidistantGrid(0:0.1:10) @test boundary_identifiers(g) == (Lower(), Upper())