|
1 | 1 | @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 | + |
3 | 22 | @test collect(partitions(8, 3)) == Any[[6, 1, 1], [5, 2, 1], [4, 3, 1], [4, 2, 2], [3, 3, 2]] |
4 | 23 | @test collect(partitions(8, 1)) == Any[[8]] |
5 | 24 | @test collect(partitions(8, 9)) == [] |
|
9 | 28 | @test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]] |
10 | 29 | @test collect(partitions([1, 2, 3, 4], 5)) == [] |
11 | 30 |
|
12 | | - @inferred first(partitions(4)) |
13 | 31 | @inferred first(partitions(8, 3)) |
14 | 32 | @inferred first(partitions([1, 2, 3])) |
15 | 33 | @inferred first(partitions([1, 2, 3, 4], 3)) |
16 | 34 |
|
17 | | - @test isa(collect(partitions(4)), Vector{Vector{Int}}) |
18 | 35 | @test isa(collect(partitions(8, 3)), Vector{Vector{Int}}) |
19 | 36 | @test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}}) |
20 | 37 | @test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}}) |
21 | 38 |
|
22 | | - @test length(partitions(0)) == 1 |
23 | | - @test length(partitions(-1)) == 0 |
24 | 39 | @test length(collect(partitions(30))) == length(partitions(30)) |
25 | 40 | @test length(collect(partitions(90, 4))) == length(partitions(90, 4)) |
26 | 41 | @test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) |
|
0 commit comments