Skip to content

Commit c4d945a

Browse files
committed
Fix integer_partitions(0)
1 parent 403dcb4 commit c4d945a

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/partitions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ function integer_partitions(n::Integer)
456456
if n < 0
457457
throw(DomainError(n, "n must be nonnegative"))
458458
elseif n == 0
459-
return Vector{Int}[]
459+
return Vector{Int}[[]]
460460
elseif n == 1
461461
return Vector{Int}[[1]]
462462
end

test/partitions.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@
2727
@test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5))
2828

2929
# integer_partitions
30-
@test integer_partitions(0) == []
31-
@test integer_partitions(5) == Any[[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]]
30+
@test integer_partitions(0) == [Int[]]
31+
@test integer_partitions(1) == [[1]]
32+
# gap> Partitions( 5 );
33+
@test integer_partitions(5) == [[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]]
3234
@test_throws DomainError integer_partitions(-1)
3335

3436
@test_throws ArgumentError prevprod([2, 3, 5], Int128(typemax(Int)) + 1)

0 commit comments

Comments
 (0)