Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jiahao committed Apr 22, 2016
1 parent 1ad05c6 commit 2aaeef7
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions test/combinations.jl
@@ -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})

0 comments on commit 2aaeef7

Please sign in to comment.