Skip to content

Commit e708971

Browse files
committed
test: add more tests for partitions(n::Integer, m::Integer)
1 parent 9e5cf7c commit e708971

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

test/partitions.jl

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,54 @@
1313
@test length(partitions(1)) == 1
1414
@test length(partitions(40)) == 37338
1515
@test length(partitions(49)) == 173525
16+
@test length(collect(partitions(30))) == length(partitions(30))
1617

1718
# Type stable
1819
@inferred first(partitions(4))
1920
@test isa(collect(partitions(4)), Vector{Vector{Int}})
2021
end
2122

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+
2552
@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]]]
2653
@test collect(partitions([1, 2, 3, 4], 3)) == Any[Any[[1, 2], [3], [4]], Any[[1, 3], [2], [4]], Any[[1], [2, 3], [4]],
2754
Any[[1, 4], [2], [3]], Any[[1], [2, 4], [3]], Any[[1], [2], [3, 4]]]
2855
@test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]]
2956
@test collect(partitions([1, 2, 3, 4], 5)) == []
3057

31-
@inferred first(partitions(8, 3))
3258
@inferred first(partitions([1, 2, 3]))
3359
@inferred first(partitions([1, 2, 3, 4], 3))
3460

35-
@test isa(collect(partitions(8, 3)), Vector{Vector{Int}})
3661
@test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}})
3762
@test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}})
3863

39-
@test length(collect(partitions(30))) == length(partitions(30))
40-
@test length(collect(partitions(90, 4))) == length(partitions(90, 4))
4164
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))
4265
@test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5))
4366

0 commit comments

Comments
 (0)