Skip to content

Commit 4cb1d9e

Browse files
StivanificationStefan Riggerinkydragon
authored
Bugfix: include empty combination (#129)
* bugfix: include empty combination, update tests --------- Co-authored-by: Stefan Rigger <[email protected]> Co-authored-by: Chengyu Han <[email protected]>
1 parent 2c358b8 commit 4cb1d9e

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/combinations.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ end
5656
Generate combinations of the elements of `a` of all orders. Chaining of order iterators
5757
is eager, but the sequence at each order is lazy.
5858
"""
59-
combinations(a) = Iterators.flatten([combinations(a, k) for k = 1:length(a)])
60-
61-
59+
combinations(a) = Iterators.flatten([combinations(a, k) for k = 0:length(a)])
6260

6361
# cool-lex combinations iterator
6462

test/combinations.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
@testset "combinations" begin
2-
@test [combinations([])...] == []
3-
@test [combinations(['a', 'b', 'c'])...] == [['a'], ['b'], ['c'], ['a', 'b'], ['a', 'c'], ['b', 'c'], ['a', 'b', 'c']]
2+
@test [combinations([])...] == [[]]
3+
@test [combinations(['a', 'b', 'c'])...] == [[],['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']]
4+
@test length(collect(combinations(1:5))) == 32
45

56
@test [combinations("abc", 3)...] == [['a', 'b', 'c']]
67
@test [combinations("abc", 2)...] == [['a', 'b'], ['a', 'c'], ['b', 'c']]

0 commit comments

Comments
 (0)