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
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), )
def test_iter_agrees_with_itertools(s, k): actual = comb.Combinations(s, k) expected = itertools.combinations(s, k) assert list(actual) == list(expected)
def test_contains_ignores_order(s, k): combinations = comb.Combinations(s, k) for combination in itertools.combinations(s, k): assert reversed(combination) in combinations
def test_contains_agrees_with_itertools(s, k): combinations = comb.Combinations(s, k) for combination in combinations: assert combination in combinations
def test_str_does_not_raise(s, k): str(comb.Combinations(s, k))
def test_len_agrees_with_itertools(s, k): actual = comb.Combinations(s, k) expected = list(itertools.combinations(s, k)) assert len(actual) == len(expected)
def test_comb_benchmark(k): comb.Combinations.clear_cache() cs = comb.Combinations(range(52), k) [cs[i] for i in range(len(cs))]