|
13 | 13 | @test length(partitions(1)) == 1 |
14 | 14 | @test length(partitions(40)) == 37338 |
15 | 15 | @test length(partitions(49)) == 173525 |
| 16 | + @test length(collect(partitions(30))) == length(partitions(30)) |
16 | 17 |
|
17 | 18 | # Type stable |
18 | 19 | @inferred first(partitions(4)) |
19 | 20 | @test isa(collect(partitions(4)), Vector{Vector{Int}}) |
20 | 21 | end |
21 | 22 |
|
22 | | - @test collect(partitions(8, 3)) == Any[[6, 1, 1], [5, 2, 1], [4, 3, 1], [4, 2, 2], [3, 3, 2]] |
23 | | - @test collect(partitions(8, 1)) == Any[[8]] |
24 | | - @test collect(partitions(8, 9)) == [] |
| 23 | + @testset "partitions(n::Integer, m::Integer)" begin |
| 24 | + @test collect(partitions(8, 1)) == [[8]] |
| 25 | + @test collect(partitions(8, 3)) == [[6, 1, 1], [5, 2, 1], [4, 3, 1], [4, 2, 2], [3, 3, 2]] |
| 26 | + @test collect(partitions(8, 8)) == [ones(Int, 8)] |
| 27 | + @test collect(partitions(8, 9)) == [] |
| 28 | + @test collect(partitions(90, 90)) == [ones(Int, 90)] |
| 29 | + @test collect(partitions(90, 91)) == [] |
| 30 | + |
| 31 | + # legnth |
| 32 | + @test length(partitions(8, 1)) == 1 |
| 33 | + @test length(partitions(8, 3)) == 5 |
| 34 | + @test length(partitions(8, 8)) == 1 |
| 35 | + @test length(partitions(8, 9)) == 0 |
| 36 | + @test length(partitions(90, 1)) == 1 |
| 37 | + # gap> NrPartitions(90, 4); |
| 38 | + @test length(partitions(90, 4)) == 5231 |
| 39 | + @test length(collect(partitions(90, 4))) == length(partitions(90, 4)) |
| 40 | + @test length(partitions(90, 90)) == 1 |
| 41 | + |
| 42 | + # Type stable |
| 43 | + @inferred first(partitions(8, 3)) |
| 44 | + @test isa(collect(partitions(8, 3)), Vector{Vector{Int}}) |
| 45 | + |
| 46 | + # errors |
| 47 | + @test_throws DomainError partitions(-1, 1) |
| 48 | + @test_throws DomainError partitions(8, 0) |
| 49 | + @test_throws DomainError partitions(8, -1) |
| 50 | + end |
| 51 | + |
25 | 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]]] |
26 | 53 | @test collect(partitions([1, 2, 3, 4], 3)) == Any[Any[[1, 2], [3], [4]], Any[[1, 3], [2], [4]], Any[[1], [2, 3], [4]], |
27 | 54 | Any[[1, 4], [2], [3]], Any[[1], [2, 4], [3]], Any[[1], [2], [3, 4]]] |
28 | 55 | @test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]] |
29 | 56 | @test collect(partitions([1, 2, 3, 4], 5)) == [] |
30 | 57 |
|
31 | | - @inferred first(partitions(8, 3)) |
32 | 58 | @inferred first(partitions([1, 2, 3])) |
33 | 59 | @inferred first(partitions([1, 2, 3, 4], 3)) |
34 | 60 |
|
35 | | - @test isa(collect(partitions(8, 3)), Vector{Vector{Int}}) |
36 | 61 | @test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}}) |
37 | 62 | @test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}}) |
38 | 63 |
|
39 | | - @test length(collect(partitions(30))) == length(partitions(30)) |
40 | | - @test length(collect(partitions(90, 4))) == length(partitions(90, 4)) |
41 | 64 | @test length(collect(partitions('a':'h'))) == length(partitions('a':'h')) |
42 | 65 | @test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5)) |
43 | 66 |
|
|
0 commit comments