From 1891db3814cdc73404f5148f96871f8bfef76331 Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Tue, 8 Aug 2023 16:56:31 -0500 Subject: [PATCH] ListOffsetArray's is_valid. --- src/AwkwardArray.jl | 7 ++++++- test/runtests.jl | 9 +++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/AwkwardArray.jl b/src/AwkwardArray.jl index fb6ed62..ebb9d86 100644 --- a/src/AwkwardArray.jl +++ b/src/AwkwardArray.jl @@ -63,7 +63,12 @@ struct ListOffsetArray{T<:Union{Int32,UInt32,Int64}} <: Content end function is_valid(x::ListOffsetArray) - true + for i = Base.firstindex(x):Base.lastindex(x) + if x.offsets[i+1] < x.offsets[i] + return false + end + end + return true end function Base.length(x::ListOffsetArray) diff --git a/test/runtests.jl b/test/runtests.jl index 033dead..2b4d13b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -39,4 +39,13 @@ using Test end @test tmp == 5 end + + begin + layout = AwkwardArray.ListOffsetArray( + [0, 3, 2, 5], + AwkwardArray.PrimitiveArray([1.1, 2.2, 3.3, 4.4, 5.5]), + ) + @test !AwkwardArray.is_valid(layout) + end + end