Skip to content

Commit 0bd13b1

Browse files
committed
test: add more tests for integer_partitions(n)
1 parent 5fd8008 commit 0bd13b1

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

test/partitions.jl

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,26 @@
2626
@test length(collect(partitions('a':'h'))) == length(partitions('a':'h'))
2727
@test length(collect(partitions('a':'h', 5))) == length(partitions('a':'h', 5))
2828

29-
# integer_partitions
30-
@test integer_partitions(0) == []
31-
@test integer_partitions(5) == Any[[1, 1, 1, 1, 1], [2, 1, 1, 1], [2, 2, 1], [3, 1, 1], [3, 2], [4, 1], [5]]
32-
@test_throws DomainError integer_partitions(-1)
29+
@testset "integer partitions" begin
30+
@test_broken integer_partitions(0) == [[]]
31+
@test integer_partitions(1) == [[1]]
32+
@test integer_partitions(2) == [[1, 1], [2]]
33+
@test integer_partitions(3) == [[1, 1, 1], [2, 1], [3]]
34+
# gap> Partitions( 5 );
35+
@test integer_partitions(5) == [
36+
[1, 1, 1, 1, 1],
37+
[2, 1, 1, 1],
38+
[2, 2, 1],
39+
[3, 1, 1],
40+
[3, 2],
41+
[4, 1],
42+
[5]
43+
]
44+
# integer_partitions <--> partitions(::Integer)
45+
@test Set(integer_partitions(5)) == Set(partitions(5))
46+
47+
@test_throws DomainError integer_partitions(-1)
48+
end
3349

3450
@test_throws ArgumentError prevprod([2, 3, 5], Int128(typemax(Int)) + 1)
3551
@test prevprod([2, 3, 5], 30) == 30

0 commit comments

Comments
 (0)