comparison 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
comparison
equal deleted inserted replaced
1258:e67cddbb8adc 1259:ee57bdb366e4
7 @testset "EquidistantGrid" begin 7 @testset "EquidistantGrid" begin
8 @test EquidistantGrid(0:0.1:10) isa EquidistantGrid 8 @test EquidistantGrid(0:0.1:10) isa EquidistantGrid
9 @test EquidistantGrid(range(0,1,length=10)) isa EquidistantGrid 9 @test EquidistantGrid(range(0,1,length=10)) isa EquidistantGrid
10 @test EquidistantGrid(LinRange(0,1,11)) isa EquidistantGrid 10 @test EquidistantGrid(LinRange(0,1,11)) isa EquidistantGrid
11 11
12 @testset "Base" begin 12 @testset "Indexing Interface" begin
13 g = EquidistantGrid(0:0.1:10)
14 @test g[1] == 0.0
15 @test g[5] == 0.4
16 @test g[101] == 10.0
17
18 @test g[begin] == 0.0
19 @test g[end] == 10.0
20
21 @test all(eachindex(g) .== 1:101)
22 end
23
24 @testset "Iterator interface" begin
13 @test eltype(EquidistantGrid(0:10)) == Int 25 @test eltype(EquidistantGrid(0:10)) == Int
14 @test eltype(EquidistantGrid(0:2:10)) == Int 26 @test eltype(EquidistantGrid(0:2:10)) == Int
15 @test eltype(EquidistantGrid(0:0.1:10)) == Float64 27 @test eltype(EquidistantGrid(0:0.1:10)) == Float64
16 @test size(EquidistantGrid(0:10)) == (11,) 28 @test size(EquidistantGrid(0:10)) == (11,)
17 @test size(EquidistantGrid(0:0.1:10)) == (101,) 29 @test size(EquidistantGrid(0:0.1:10)) == (101,)
30
31 @test collect(EquidistantGrid(0:0.1:0.5)) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
32
33 @test Base.IteratorSize(EquidistantGrid{Float64, StepRange{Float64}}) == Base.HasShape{1}()
34 end
35
36 @testset "Base" begin
18 @test ndims(EquidistantGrid(0:10)) == 1 37 @test ndims(EquidistantGrid(0:10)) == 1
19 end 38 end
20 39
21 @testset "spacing" begin 40 @testset "spacing" begin
22 @test spacing(EquidistantGrid(0:10)) == 1 41 @test spacing(EquidistantGrid(0:10)) == 1
24 end 43 end
25 44
26 @testset "inverse_spacing" begin 45 @testset "inverse_spacing" begin
27 @test inverse_spacing(EquidistantGrid(0:10)) == 1 46 @test inverse_spacing(EquidistantGrid(0:10)) == 1
28 @test inverse_spacing(EquidistantGrid(0:0.1:10)) == 10 47 @test inverse_spacing(EquidistantGrid(0:0.1:10)) == 10
29 end
30
31 @testset "collect" begin
32 g = EquidistantGrid(0:0.1:0.5)
33 @test collect(g) == [0.0, 0.1, 0.2, 0.3, 0.4, 0.5]
34 end
35
36 @testset "getindex" begin
37 g = EquidistantGrid(0:0.1:10)
38 @test g[1] == 0.0
39 @test g[5] == 0.4
40 @test g[101] == 10.0
41
42 @test g[begin] == 0.0
43 @test g[end] == 10.0
44 end 48 end
45 49
46 @testset "boundary_identifiers" begin 50 @testset "boundary_identifiers" begin
47 g = EquidistantGrid(0:0.1:10) 51 g = EquidistantGrid(0:0.1:10)
48 @test boundary_identifiers(g) == (Lower(), Upper()) 52 @test boundary_identifiers(g) == (Lower(), Upper())