view test/Grids/zero_dim_grid_test.jl @ 1354:150313ed2cae

Merge refactor/grids (missed delete of a note) Changes from previous merge: * `EquidistantGrid` is now only a 1D thing. * Higher dimensions are supported through `TensorGrid`. * The old behavior of `EquidistantGrid` has been moved to the function `equidistant_grid`. * Grids embedded in higher dimensions are now supported through tensor products with `ZeroDimGrid`s. * Vector valued grid functions are now supported and the default element type is `SVector`. * Grids are now expected to support Julia's indexing and iteration interface. * `eval_on` can be called with both `f(x,y,...)` and `f(x̄)`.
author Jonatan Werpers <jonatan@werpers.com>
date Sat, 20 May 2023 14:19:20 +0200
parents dbddd0f61bde
children 4ad1282f8bab
line wrap: on
line source

using Test
using Sbplib.Grids
using StaticArrays

@testset "ZeroDimGrid" begin
    @test ZeroDimGrid(1) isa ZeroDimGrid{Int}
    @test ZeroDimGrid([1,2,3]) isa ZeroDimGrid{Vector{Int}}
    @test ZeroDimGrid(@SVector[1.0,2.0]) isa ZeroDimGrid{SVector{2,Float64}}

    @testset "Indexing Interface" begin
        g = ZeroDimGrid(@SVector[1,2])

        @test g[] == [1,2]
        @test eachindex(g) == CartesianIndices(())
    end

    @testset "Iterator interface" begin
        g = ZeroDimGrid(@SVector[1,2])

        @test Base.IteratorSize(g) == Base.HasShape{0}()
        @test eltype(g) == SVector{2,Int}
        @test length(g) == 1
        @test size(g) == ()
        @test collect(g) == fill(@SVector[1,2])
    end

    @testset "refine" begin
        @test refine(ZeroDimGrid(@SVector[1.0,2.0]),1) == ZeroDimGrid(@SVector[1.0,2.0])
        @test refine(ZeroDimGrid(@SVector[1.0,2.0]),2) == ZeroDimGrid(@SVector[1.0,2.0])
    end

    @testset "coarsen" begin
        @test coarsen(ZeroDimGrid(@SVector[1.0,2.0]),1) == ZeroDimGrid(@SVector[1.0,2.0])
        @test coarsen(ZeroDimGrid(@SVector[1.0,2.0]),2) == ZeroDimGrid(@SVector[1.0,2.0])
    end

    @testset "boundary_identifiers" begin
        @test boundary_identifiers(ZeroDimGrid(@SVector[1.0,2.0])) == ()
    end

    @testset "boundary_grid" begin
        @test_throws ArgumentError("ZeroDimGrid has no boundaries") boundary_grid(ZeroDimGrid(@SVector[1.0,2.0]), :bid)
    end
end