Mercurial > repos > public > sbplib_julia
diff test/Grids/equidistant_grid_test.jl @ 1854:654a2b7e6824 tooling/benchmarks
Merge default
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 11 Jan 2025 10:19:47 +0100 |
parents | 471a948cd2b2 |
children | 03894fd7b132 871f3f1decea |
line wrap: on
line diff
--- a/test/Grids/equidistant_grid_test.jl Wed May 31 08:59:34 2023 +0200 +++ b/test/Grids/equidistant_grid_test.jl Sat Jan 11 10:19:47 2025 +0100 @@ -1,7 +1,6 @@ -using Sbplib.Grids +using Diffinitive.Grids using Test -using Sbplib.RegionIndices -using Sbplib.LazyTensors +using Diffinitive.LazyTensors @testset "EquidistantGrid" begin @@ -19,6 +18,9 @@ @test g[end] == 10.0 @test all(eachindex(g) .== 1:101) + + @test firstindex(g) == 1 + @test lastindex(g) == 101 end @testset "Iterator interface" begin @@ -28,6 +30,8 @@ @test size(EquidistantGrid(0:10)) == (11,) @test size(EquidistantGrid(0:0.1:10)) == (101,) + @test size(EquidistantGrid(0:0.1:10),1) == 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}() @@ -35,6 +39,10 @@ @testset "Base" begin @test ndims(EquidistantGrid(0:10)) == 1 + + g = EquidistantGrid(0:0.1:10) + @test axes(g,1) == 1:101 + @test axes(g) == (1:101,) end @testset "spacing" begin @@ -47,16 +55,32 @@ @test inverse_spacing(EquidistantGrid(0:0.1:10)) == 10 end + @testset "min_spacing" begin + @test min_spacing(EquidistantGrid(0:10)) == 1 + @test min_spacing(EquidistantGrid(0:0.1:10)) == 0.1 + end + @testset "boundary_identifiers" begin g = EquidistantGrid(0:0.1:10) - @test boundary_identifiers(g) == (Lower(), Upper()) + @test boundary_identifiers(g) == (LowerBoundary(), UpperBoundary()) @inferred boundary_identifiers(g) end @testset "boundary_grid" begin g = EquidistantGrid(0:0.1:1) - @test boundary_grid(g, Lower()) == ZeroDimGrid(0.0) - @test boundary_grid(g, Upper()) == ZeroDimGrid(1.0) + @test boundary_grid(g, LowerBoundary()) == ZeroDimGrid(0.0) + @test boundary_grid(g, UpperBoundary()) == ZeroDimGrid(1.0) + end + + @testset "boundary_indices" begin + g = EquidistantGrid(0:0.1:1) + @test boundary_indices(g, LowerBoundary()) == (1,) + @test boundary_indices(g, UpperBoundary()) == (11,) + + g = EquidistantGrid(2:0.1:10) + @test boundary_indices(g, LowerBoundary()) == (1,) + @test boundary_indices(g, UpperBoundary()) == (81,) + end @testset "refine" begin @@ -85,29 +109,37 @@ @testset "equidistant_grid" begin - @test equidistant_grid(4,0.0,1.0) isa EquidistantGrid - @test equidistant_grid((4,3),(0.0,0.0),(8.0,5.0)) isa TensorGrid + @test equidistant_grid(0.0,1.0, 4) isa EquidistantGrid + @test equidistant_grid((0.0,0.0),(8.0,5.0), 4, 3) isa TensorGrid + @test equidistant_grid((0.0,),(8.0,), 4) isa TensorGrid # constuctor - @test_throws DomainError equidistant_grid(0,0.0,1.0) - @test_throws DomainError equidistant_grid(1,1.0,1.0) - @test_throws DomainError equidistant_grid(1,1.0,-1.0) + @test_throws DomainError equidistant_grid(0.0, 1.0, 0) + @test_throws DomainError equidistant_grid(1.0, 1.0, 1) + @test_throws DomainError equidistant_grid(1.0, -1.0, 1) - @test_throws DomainError equidistant_grid((0,0),(0.0,0.0),(1.0,1.0)) - @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(1.0,1.0)) - @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(-1.0,-1.0)) + @test_throws DomainError equidistant_grid((0.0,0.0),(1.0,1.0), 0, 0) + @test_throws DomainError equidistant_grid((1.0,1.0),(1.0,1.0), 1, 1) + @test_throws DomainError equidistant_grid((1.0,1.0),(-1.0,-1.0), 1, 1) + + @test_throws ArgumentError equidistant_grid((0.0,),(8.0,5.0), 4, 3, 4) @testset "Base" begin - @test eltype(equidistant_grid(4,0.0,1.0)) == Float64 - @test eltype(equidistant_grid((4,3),(0,0),(1,3))) <: AbstractVector{Float64} - @test size(equidistant_grid(4,0.0,1.0)) == (4,) - @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) - @test ndims(equidistant_grid(4,0.0,1.0)) == 1 - @test ndims(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == 2 + @test eltype(equidistant_grid(0.0, 1.0, 4)) == Float64 + @test eltype(equidistant_grid((0,0),(1,3), 4, 3)) <: AbstractVector{Float64} + + @test size(equidistant_grid(0.0, 1.0, 4)) == (4,) + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == (5,3) + + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 1) == 5 + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 2) == 3 + + @test ndims(equidistant_grid(0.0, 1.0, 4)) == 1 + @test ndims(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == 2 end @testset "getindex" begin - g = equidistant_grid((5,3), (-1.0,0.0), (0.0,7.11)) + g = equidistant_grid((-1.0,0.0), (0.0,7.11), 5, 3) gp = collect(g); p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11);