Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Band-aid around JuliaCollections/Iterators.jl#56
- Loading branch information
Showing
1 changed file
with
26 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,40 @@ | ||
using Combinatorics | ||
using Base.Test | ||
|
||
@test collect(combinations([])) == [] | ||
@test collect(combinations(['a', 'b', 'c'])) == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] | ||
@test [combinations([])...] == [] | ||
@test [combinations(['a', 'b', 'c'])...] == Any[['a'],['b'],['c'],['a','b'],['a','c'],['b','c'],['a','b','c']] | ||
|
||
@test collect(combinations("abc",3)) == Any[['a','b','c']] | ||
@test collect(combinations("abc",2)) == Any[['a','b'],['a','c'],['b','c']] | ||
@test collect(combinations("abc",1)) == Any[['a'],['b'],['c']] | ||
@test collect(combinations("abc",0)) == Any[[]] | ||
@test collect(combinations("abc",-1)) == [] | ||
@test [combinations("abc",3)...] == Any[['a','b','c']] | ||
@test [combinations("abc",2)...] == Any[['a','b'],['a','c'],['b','c']] | ||
@test [combinations("abc",1)...] == Any[['a'],['b'],['c']] | ||
@test [combinations("abc",0)...] == Any[[]] | ||
@test [combinations("abc",-1)...] == [] | ||
|
||
@test collect(filter(x->(iseven(x[1])),combinations([1,2,3],2))) == Any[[2,3]] | ||
@test filter(x->iseven(x[1]),[combinations([1,2,3],2)...]) == Any[[2,3]] | ||
|
||
# multiset_combinations | ||
@test collect(multiset_combinations("aabc", 5)) == Any[] | ||
@test collect(multiset_combinations("aabc", 2)) == Any[['a','a'],['a','b'],['a','c'],['b','c']] | ||
@test collect(multiset_combinations("aabc", 1)) == Any[['a'],['b'],['c']] | ||
@test collect(multiset_combinations("aabc", 0)) == Any[Char[]] | ||
@test collect(multiset_combinations("aabc", -1)) == Any[] | ||
@test collect(multiset_combinations("", 1)) == Any[] | ||
@test collect(multiset_combinations("", 0)) == Any[Char[]] | ||
@test collect(multiset_combinations("", -1)) == Any[] | ||
@test [multiset_combinations("aabc", 5)...] == Any[] | ||
@test [multiset_combinations("aabc", 2)...] == Any[['a','a'],['a','b'],['a','c'],['b','c']] | ||
@test [multiset_combinations("aabc", 1)...] == Any[['a'],['b'],['c']] | ||
@test [multiset_combinations("aabc", 0)...] == Any[Char[]] | ||
@test [multiset_combinations("aabc", -1)...] == Any[] | ||
@test [multiset_combinations("", 1)...] == Any[] | ||
@test [multiset_combinations("", 0)...] == Any[Char[]] | ||
@test [multiset_combinations("", -1)...] == Any[] | ||
|
||
# with_replacement_combinations | ||
@test collect(with_replacement_combinations("abc", 2)) == Any[['a','a'],['a','b'],['a','c'], | ||
@test [with_replacement_combinations("abc", 2)...] == Any[['a','a'],['a','b'],['a','c'], | ||
['b','b'],['b','c'],['c','c']] | ||
@test collect(with_replacement_combinations("abc", 1)) == Any[['a'],['b'],['c']] | ||
@test collect(with_replacement_combinations("abc", 0)) == Any[Char[]] | ||
@test collect(with_replacement_combinations("abc", -1)) == Any[] | ||
@test collect(with_replacement_combinations("", 1)) == Any[] | ||
@test collect(with_replacement_combinations("", 0)) == Any[Char[]] | ||
@test collect(with_replacement_combinations("", -1)) == Any[] | ||
@test [with_replacement_combinations("abc", 1)...] == Any[['a'],['b'],['c']] | ||
@test [with_replacement_combinations("abc", 0)...] == Any[Char[]] | ||
@test [with_replacement_combinations("abc", -1)...] == Any[] | ||
@test [with_replacement_combinations("", 1)...] == Any[] | ||
@test [with_replacement_combinations("", 0)...] == Any[Char[]] | ||
@test [with_replacement_combinations("", -1)...] == Any[] | ||
|
||
|
||
#cool-lex iterator | ||
@test_throws DomainError collect(CoolLexCombinations(-1, 1)) | ||
@test_throws DomainError collect(CoolLexCombinations(5, 0)) | ||
@test collect(CoolLexCombinations(4,2)) == Vector[[1,2], [2,3], [1,3], [2,4], [3,4], [1,4]] | ||
@test_throws DomainError [CoolLexCombinations(-1, 1)...] | ||
@test_throws DomainError [CoolLexCombinations(5, 0)...] | ||
@test [CoolLexCombinations(4,2)...] == Vector[[1,2], [2,3], [1,3], [2,4], [3,4], [1,4]] | ||
@test isa(start(CoolLexCombinations(1000, 20)), Combinatorics.CoolLexIterState{BigInt}) |