Skip to content

Commit ffee802

Browse files
committed
test: add more tests for partitions(s::AbstractVector, m::Int)
1 parent 57ece4f commit ffee802

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

test/partitions.jl

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,34 @@
6666
@test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}})
6767
end
6868

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))
7692

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
7897

7998
@testset "integer partitions" begin
8099
@test_broken integer_partitions(0) == [[]]

0 commit comments

Comments
 (0)