|
49 | 49 | @test_throws DomainError partitions(8, -1) |
50 | 50 | end |
51 | 51 |
|
52 | | - @test collect(partitions([1, 2, 3])) == Any[Any[[1, 2, 3]], Any[[1, 2], [3]], Any[[1, 3], [2]], Any[[1], [2, 3]], Any[[1], [2], [3]]] |
| 52 | + @testset "partitions(s::AbstractVector)" begin |
| 53 | + @test collect(partitions([1])) == [[[1]]] |
| 54 | + @test collect(partitions([1, 2])) == [[[1, 2]], [[1], [2]]] |
| 55 | + @test collect(partitions([1, 2, 3])) == [[[1, 2, 3]], [[1, 2], [3]], [[1, 3], [2]], [[1], [2, 3]], [[1], [2], [3]]] |
| 56 | + @test collect(partitions(1:3)) == collect(partitions([1, 2, 3])) |
| 57 | + @test collect(partitions('a':'b')) == [[['a', 'b']], [['a'], ['b']]] |
| 58 | + |
| 59 | + # length: https://oeis.org/A000110 |
| 60 | + @test length(partitions(1:10)) == 115975 |
| 61 | + @test length(partitions(1:20)) == 51724158235372 |
| 62 | + @test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) |
| 63 | + |
| 64 | + # Type stable |
| 65 | + @inferred first(partitions([1, 2, 3])) |
| 66 | + @test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}}) |
| 67 | + end |
| 68 | + |
53 | 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]], |
54 | 70 | Any[[1, 4], [2], [3]], Any[[1], [2, 4], [3]], Any[[1], [2], [3, 4]]] |
55 | 71 | @test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]] |
56 | 72 | @test collect(partitions([1, 2, 3, 4], 5)) == [] |
57 | 73 |
|
58 | | - @inferred first(partitions([1, 2, 3])) |
59 | 74 | @inferred first(partitions([1, 2, 3, 4], 3)) |
60 | | - |
61 | | - @test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}}) |
62 | 75 | @test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}}) |
63 | 76 |
|
64 | | - @test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) |
65 | 77 | @test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5)) |
66 | 78 |
|
67 | 79 | @testset "integer partitions" begin |
|
0 commit comments