|
66 | 66 | @test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}}) |
67 | 67 | end |
68 | 68 |
|
69 | | - @test collect(partitions([1, 2, 3, 4], 3)) == Any[Any[[1, 2], [3], [4]], Any[[1, 3], [2], [4]], Any[[1], [2, 3], [4]], |
70 | | - Any[[1, 4], [2], [3]], Any[[1], [2, 4], [3]], Any[[1], [2], [3, 4]]] |
71 | | - @test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]] |
72 | | - @test collect(partitions([1, 2, 3, 4], 5)) == [] |
73 | | - |
74 | | - @inferred first(partitions([1, 2, 3, 4], 3)) |
75 | | - @test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}}) |
| 69 | + @testset "partitions(s::AbstractVector, m::Int)" begin |
| 70 | + @test collect(partitions(1:3, 2)) == [ |
| 71 | + [[1, 2], [3]], |
| 72 | + [[1, 3], [2]], |
| 73 | + [[1], [2, 3]], |
| 74 | + ] |
| 75 | + @test collect(partitions([1, 2, 3, 4], 1)) == [[[1, 2, 3, 4]]] |
| 76 | + @test collect(partitions([1, 2, 3, 4], 3)) == [ |
| 77 | + [[1, 2], [3], [4]], [[1, 3], [2], [4]], [[1], [2, 3], [4]], |
| 78 | + [[1, 4], [2], [3]], [[1], [2, 4], [3]], [[1], [2], [3, 4]] |
| 79 | + ] |
| 80 | + @test collect(partitions([1, 2, 3, 4], 4)) == [[[1], [2], [3], [4]]] |
| 81 | + @test collect(partitions([1, 2, 3, 4], 5)) == [] |
| 82 | + |
| 83 | + # length: Stirling numbers of the second kind |
| 84 | + # https://dlmf.nist.gov/26.8#T2 |
| 85 | + @test length(partitions(1:3, 2)) == 3 |
| 86 | + @test length(partitions([1, 2, 3, 4], 3)) == 6 |
| 87 | + @test length(partitions(1:10, 4)) == 34105 |
| 88 | + @test length(partitions(1:10, 5)) == 42525 |
| 89 | + @test length(partitions(1:10, 5)) == stirlings2(10, 5) |
| 90 | + @test length(partitions(1:10, 6)) == 22827 |
| 91 | + @test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5)) |
76 | 92 |
|
77 | | - @test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5)) |
| 93 | + # Type stable |
| 94 | + @inferred first(partitions([1, 2, 3, 4], 3)) |
| 95 | + @test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}}) |
| 96 | + end |
78 | 97 |
|
79 | 98 | @testset "integer partitions" begin |
80 | 99 | @test_broken integer_partitions(0) == [[]] |
|
0 commit comments