Skip to content

Commit

Permalink
delete unique_key_seq
Browse files Browse the repository at this point in the history
  • Loading branch information
tandav committed Sep 17, 2023
1 parent 1ae1028 commit 6874062
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 28 deletions.
4 changes: 0 additions & 4 deletions opseq/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def __init__(
constraints: Iterable[Constraint[Op]] = (),
prefix_constraints: Iterable[Constraint[Op]] = (),
unique_key_op: UniqueKeyOp[Op] | None = None,
unique_key_seq: UniqueKeySeq[Op] | None = None,
):
self.n = n
self.generator = generator
Expand All @@ -39,9 +38,6 @@ def __init__(
if unique_key_op is not None:
self.prefix_constraints.append(constraints_.UniqueOp(unique_key_op))

if unique_key_seq is not None:
self.constraints.append(constraints_.UniqueSeq(unique_key_seq, self.seen_keys))

def __iter__(self) -> Generator[Seq[Op], None, None]:
self.seen_keys.clear()
self.prefix_queue = multiprocessing.Queue()
Expand Down
13 changes: 0 additions & 13 deletions opseq/constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,6 @@ def __call__(self, seq: Seq[Op]) -> bool:
return len(seq) == len(set(map(self.key, seq)))


class UniqueSeq:
def __init__(self, key, seen_keys):
self.key = key
self.seen_keys = seen_keys

def __call__(self, seq: Seq[Op]) -> bool:
k = self.key(seq)
if k in self.seen_keys:
return False
self.seen_keys.add(k)
return True


class LenConstraint:
def __init__(self, length: int, constraint: tp.Callable[[Seq[Op]], bool]):
self.length = length
Expand Down
11 changes: 0 additions & 11 deletions tests/constraints_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ def test_constraint(generator1, constraint, expected):
assert list(OpSeq(2, generator1, constraints=[constraint])) == expected


@pytest.mark.parametrize('key, expected', [
(sum, [(0, 0), (0, 1), (1, 1)]),
(frozenset, [(0, 0), (0, 1), (1, 1)]),
(lambda seq: seq, [(0, 0), (0, 1), (1, 0), (1, 1)]),
])
def test_unique_key_seq(generator1, key, expected):
opseq = OpSeq(2, generator1, unique_key_seq=key)
assert list(opseq) == expected
assert list(opseq) == expected # test multiple iterations give same result


@pytest.mark.parametrize('generator, key, expected', [
(AppendOp([0, 1]), identity, [(0, 1), (1, 0)]),
(AppendOp(['a', 'b']), str.lower, [('a', 'b'), ('b', 'a')]),
Expand Down

0 comments on commit 6874062

Please sign in to comment.