Skip to content

Commit a649db6

Browse files
committed
test: add more tests for partitions(s::AbstractVector)
1 parent 36365ae commit a649db6

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

test/partitions.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,31 @@
4949
@test_throws DomainError partitions(8, -1)
5050
end
5151

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+
5369
@test collect(partitions([1, 2, 3, 4], 3)) == Any[Any[[1, 2], [3], [4]], Any[[1, 3], [2], [4]], Any[[1], [2, 3], [4]],
5470
Any[[1, 4], [2], [3]], Any[[1], [2, 4], [3]], Any[[1], [2], [3, 4]]]
5571
@test collect(partitions([1, 2, 3, 4], 1)) == Any[Any[[1, 2, 3, 4]]]
5672
@test collect(partitions([1, 2, 3, 4], 5)) == []
5773

58-
@inferred first(partitions([1, 2, 3]))
5974
@inferred first(partitions([1, 2, 3, 4], 3))
60-
61-
@test isa(collect(partitions([1, 2, 3])), Vector{Vector{Vector{Int}}})
6275
@test isa(collect(partitions([1, 2, 3, 4], 3)), Vector{Vector{Vector{Int}}})
6376

64-
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))
6577
@test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5))
6678

6779
@testset "integer partitions" begin

0 commit comments

Comments
 (0)