view test/Grids/zero_dim_grid_test.jl @ 1260:8b9a77d2dc91 refactor/grids

Add tests and make them pass for ZeroDimGrid
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 23 Feb 2023 12:22:18 +0100
parents 6323d2fe3b4f
children b0819f6b9d4a
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
end