Skip to content

Commit 1ec9e62

Browse files
committed
test: add more tests for partitions(n::Integer)
1 parent 763913c commit 1ec9e62

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

test/partitions.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
@testset "partitions" begin
2-
@test collect(partitions(4)) == Any[[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
2+
3+
@testset "partitions(n::Integer)" begin
4+
@test_broken collect(partitions(0)) == [[]]
5+
@test collect(partitions(1)) == [[1]]
6+
@test collect(partitions(2)) == [[2], [1, 1]]
7+
@test collect(partitions(3)) == [[3], [2, 1], [1, 1, 1]]
8+
@test collect(partitions(4)) == [[4], [3, 1], [2, 2], [2, 1, 1], [1, 1, 1, 1]]
9+
10+
# Partition function p(n): https://oeis.org/A000041
11+
@test length(partitions(-1)) == 0
12+
@test length(partitions(0)) == 1
13+
@test length(partitions(1)) == 1
14+
@test length(partitions(40)) == 37338
15+
@test length(partitions(49)) == 173525
16+
17+
# Type stable
18+
@inferred first(partitions(4))
19+
@test isa(collect(partitions(4)), Vector{Vector{Int}})
20+
end
21+
322
@test collect(partitions(8, 3)) == Any[[6, 1, 1], [5, 2, 1], [4, 3, 1], [4, 2, 2], [3, 3, 2]]
423
@test collect(partitions(8, 1)) == Any[[8]]
524
@test collect(partitions(8, 9)) == []
@@ -9,18 +28,14 @@
928
@test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]]
1029
@test collect(partitions([1, 2, 3, 4], 5)) == []
1130

12-
@inferred first(partitions(4))
1331
@inferred first(partitions(8, 3))
1432
@inferred first(partitions([1, 2, 3]))
1533
@inferred first(partitions([1, 2, 3, 4], 3))
1634

17-
@test isa(collect(partitions(4)), Vector{Vector{Int}})
1835
@test isa(collect(partitions(8, 3)), Vector{Vector{Int}})
1936
@test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}})
2037
@test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}})
2138

22-
@test length(partitions(0)) == 1
23-
@test length(partitions(-1)) == 0
2439
@test length(collect(partitions(30))) == length(partitions(30))
2540
@test length(collect(partitions(90, 4))) == length(partitions(90, 4))
2641
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))

0 commit comments

Comments
 (0)