예제 #1
0
def test_contains_by_example():
    combinations = comb.Combinations("AABC", 2)
    assert "AA" in combinations  # Treats every element as unique
    assert "AB" in combinations  # A straight forward case
    assert "BB" not in combinations  # Combinations are without replacement
    assert "AAB" not in combinations  # Wrong length (too long)
    assert "A" not in combinations  # Wrong length (too short)
    assert "CA" in combinations  # Order does not matter
예제 #2
0
def test_getitem_agrees_with_itertools(s, k):
    actual = comb.Combinations(s, k)
    expected = list(itertools.combinations(s, k))
    for i in range(-2 * len(expected), 2 * len(expected)):
        assert_equivalent_behaviour(
            functools.partial(actual.__getitem__, i),
            functools.partial(expected.__getitem__, i),
        )
예제 #3
0
def test_iter_agrees_with_itertools(s, k):
    actual = comb.Combinations(s, k)
    expected = itertools.combinations(s, k)
    assert list(actual) == list(expected)
예제 #4
0
def test_contains_ignores_order(s, k):
    combinations = comb.Combinations(s, k)
    for combination in itertools.combinations(s, k):
        assert reversed(combination) in combinations
예제 #5
0
def test_contains_agrees_with_itertools(s, k):
    combinations = comb.Combinations(s, k)
    for combination in combinations:
        assert combination in combinations
예제 #6
0
def test_str_does_not_raise(s, k):
    str(comb.Combinations(s, k))
예제 #7
0
def test_len_agrees_with_itertools(s, k):
    actual = comb.Combinations(s, k)
    expected = list(itertools.combinations(s, k))
    assert len(actual) == len(expected)
예제 #8
0
def test_comb_benchmark(k):
    comb.Combinations.clear_cache()
    cs = comb.Combinations(range(52), k)
    [cs[i] for i in range(len(cs))]