Skip to content

Commit 87f7e23

Browse files
committed
Fix partitions(0), closes #143
1 parent e005ee0 commit 87f7e23

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/partitions.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ end
1717
Base.length(p::IntegerPartitions) = npartitions(p.n)
1818
Base.eltype(p::IntegerPartitions) = Vector{Int}
1919

20-
function Base.iterate(p::IntegerPartitions, xs = Int[])
20+
function Base.iterate(p::IntegerPartitions, xs = nothing)
21+
if xs === nothing
22+
p.n == 0 && return Int[], Int[]
23+
xs = Int[]
24+
end
2125
length(xs) == p.n && return
2226
xs = nextpartition(p.n,xs)
2327
(xs, xs)

test/partitions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@testset "partitions" begin
22

33
@testset "partitions(n::Integer)" begin
4-
@test_broken collect(partitions(0)) == [[]]
4+
@test collect(partitions(0)) == [[]]
55
@test collect(partitions(1)) == [[1]]
66
@test collect(partitions(2)) == [[2], [1, 1]]
77
@test collect(partitions(3)) == [[3], [2, 1], [1, 1, 1]]

0 commit comments

Comments
 (0)