Mercurial > repos > public > sbplib_julia
changeset 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 | e67cddbb8adc |
children | 8b9a77d2dc91 |
files | src/Grids/equidistant_grid.jl test/Grids/equidistant_grid_test.jl |
diffstat | 2 files changed, 21 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Grids/equidistant_grid.jl Thu Feb 23 11:40:25 2023 +0100 +++ b/src/Grids/equidistant_grid.jl Thu Feb 23 12:22:00 2023 +0100 @@ -17,7 +17,7 @@ Base.iterate(g::EquidistantGrid) = iterate(g.points) Base.iterate(g::EquidistantGrid, state) = iterate(g.points, state) -Base.IteratorSize(::Type{EquidistantGrid}) = Base.HasShape{1}() +Base.IteratorSize(::Type{EquidistantGrid{T,R}}) where {T,R} = Base.HasShape{1}() Base.eltype(::Type{EquidistantGrid{T}}) where T = T Base.length(g::EquidistantGrid) = length(g.points) Base.size(g::EquidistantGrid) = size(g.points)
--- 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())