From 4aecd552865febcfd49460dadc0624d30e663554 Mon Sep 17 00:00:00 2001 From: Fabian Gans Date: Fri, 6 Oct 2023 10:47:10 +0200 Subject: [PATCH] some more checks --- src/chunks.jl | 2 ++ test/runtests.jl | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/chunks.jl b/src/chunks.jl index 29dc47a..633a051 100644 --- a/src/chunks.jl +++ b/src/chunks.jl @@ -24,6 +24,8 @@ struct RegularChunks <: ChunkType s::Int function RegularChunks(cs::Int,offset::Int,s::Int) cs>0 || throw(ArgumentError("Chunk sizes must be strictly positive")) + -1 < offset < cs || throw(ArgumentError("Offsets must be positive and smaller than the chunk size")) + s >= 0 || throw(ArgumentError("Negative dimension lengths are not allowed")) new(cs,offset,s) end end diff --git a/test/runtests.jl b/test/runtests.jl index bf3fce9..bccd9c7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -247,6 +247,9 @@ end @test_throws BoundsError a2[0] @test_throws BoundsError a2[11] @test_throws ArgumentError RegularChunks(0,2,10) + @test_throws ArgumentError RegularChunks(2,-1,10) + @test_throws ArgumentError RegularChunks(2,2,10) + @test_throws ArgumentError RegularChunks(5,2,-1) b1 = IrregularChunks(; chunksizes=[3, 3, 4, 3, 3]) @test b1[1] == 1:3 @test b1[2] == 4:6