diff --git a/src/partitions.jl b/src/partitions.jl index 36ffb79..9c9b6d5 100644 --- a/src/partitions.jl +++ b/src/partitions.jl @@ -646,7 +646,7 @@ function integer_partitions(n::Integer) if n < 0 throw(DomainError(n, "n must be nonnegative")) elseif n == 0 - return Vector{Int}[] + return Vector{Int}[[]] elseif n == 1 return Vector{Int}[[1]] end diff --git a/test/partitions.jl b/test/partitions.jl index fba1eb6..311d633 100644 --- a/test/partitions.jl +++ b/test/partitions.jl @@ -96,7 +96,7 @@ end @testset "integer partitions" begin - @test_broken integer_partitions(0) == [[]] + @test integer_partitions(0) == [Int[]] @test integer_partitions(1) == [[1]] @test integer_partitions(2) == [[1, 1], [2]] @test integer_partitions(3) == [[1, 1, 1], [2, 1], [3]] @@ -113,6 +113,16 @@ # integer_partitions <--> partitions(::Integer) @test Set(integer_partitions(5)) == Set(partitions(5)) + # Partition function p(n): https://oeis.org/A000041 + @test length(integer_partitions(0)) == 1 + @test length(integer_partitions(1)) == 1 + @test length(integer_partitions(2)) == 2 + @test length(integer_partitions(3)) == 3 + @test length(integer_partitions(4)) == 5 + @test length(integer_partitions(5)) == 7 + @test length(integer_partitions(40)) == 37338 + @test length(integer_partitions(49)) == 173525 + @test_throws DomainError integer_partitions(-1) end