diff --git a/src/partitions.jl b/src/partitions.jl index 9c9b6d5..23a2eef 100644 --- a/src/partitions.jl +++ b/src/partitions.jl @@ -17,7 +17,11 @@ end Base.length(p::IntegerPartitions) = npartitions(p.n) Base.eltype(p::IntegerPartitions) = Vector{Int} -function Base.iterate(p::IntegerPartitions, xs = Int[]) +function Base.iterate(p::IntegerPartitions, xs = nothing) + if xs === nothing + p.n == 0 && return Int[], Int[] + xs = Int[] + end length(xs) == p.n && return xs = nextpartition(p.n,xs) (xs, xs) diff --git a/test/partitions.jl b/test/partitions.jl index 311d633..0bd0d60 100644 --- a/test/partitions.jl +++ b/test/partitions.jl @@ -1,7 +1,7 @@ @testset "partitions" begin @testset "partitions(n::Integer)" begin - @test_broken collect(partitions(0)) == [[]] + @test collect(partitions(0)) == [[]] @test collect(partitions(1)) == [[1]] @test collect(partitions(2)) == [[2], [1, 1]] @test collect(partitions(3)) == [[3], [2, 1], [1, 1, 1]]