def test_seen_len0(): assert not len(Seen()) assert len(Seen({T(1), T(2), T(3)})) == 3 assert len(Seen(seenlist=[[T(0), T(0)], [T(1), T(1)], [T(2), T(2)]])) == 3 assert len( Seen({T(1), T(2), T(3)}, seenlist=[[T(0), T(0)], [T(1), T(1)], [T(2), T(2)]])) == 6
def test_seen_containsadd0(): x = Seen() assert not x.contains_add(T(1)) assert not x.contains_add(T([0, 0])) assert T(1) in x assert T([0, 0]) in x assert x == Seen({T(1)}, [T([0, 0])])
def test_seen_cmpfailure1(): s1 = Seen({_hf.FailEqWithHash()}) s2 = Seen({_hf.FailEqWithHash()}) with pytest.raises(_hf.FailEqWithHash.EXC_TYP, match=_hf.FailEqWithHash.EXC_MSG): s1 == s2 with pytest.raises(_hf.FailEqWithHash.EXC_TYP, match=_hf.FailEqWithHash.EXC_MSG): s1 != s2
def test_seen_cmpfailure2(): s1 = Seen(set(), [_hf.FailEqWithHash()]) s2 = Seen(set(), [_hf.FailEqWithHash()]) with pytest.raises(_hf.FailEqWithHash.EXC_TYP, match=_hf.FailEqWithHash.EXC_MSG): s1 == s2 with pytest.raises(_hf.FailEqWithHash.EXC_TYP, match=_hf.FailEqWithHash.EXC_MSG): s1 != s2
def test_uniqueeverseen_getter1(): t = unique_everseen([T(1), T([0, 0]), T(3)]) assert not t.seen assert t.key is None assert next(t) == T(1) assert t.seen == Seen({T(1)}) assert t.key is None assert next(t) == T([0, 0]) assert T(1) in t.seen assert T([0, 0]) in t.seen assert t.key is None assert next(t) == T(3) assert t.seen == Seen({T(1), T(3)}, [T([0, 0])]) assert t.key is None
def test_uniqueeverseen_getter2(): t = unique_everseen([T(1), T([0, 0]), T(3)], iteration_utilities.return_identity) assert not t.seen assert t.key is iteration_utilities.return_identity assert next(t) == T(1) assert t.seen == Seen({T(1)}) assert t.key is iteration_utilities.return_identity assert next(t) == T([0, 0]) assert T(1) in t.seen assert T([0, 0]) in t.seen assert t.key is iteration_utilities.return_identity assert next(t) == T(3) assert t.seen == Seen({T(1), T(3)}, [T([0, 0])]) assert t.key is iteration_utilities.return_identity
def test_seen_othercmp1(): # other comparisons than == or != fail with pytest.raises(TypeError): Seen(set()) < Seen(set()) with pytest.raises(TypeError): Seen(set()) <= Seen(set()) with pytest.raises(TypeError): Seen(set()) >= Seen(set()) with pytest.raises(TypeError): Seen(set()) > Seen(set())
def part2(text): lines = text.strip().split() length = len(lines[0]) commons = [Seen() for _ in range(length)] for line in lines: for i, common in enumerate(commons): string = f"{line[:i]}{line[i + 1:]}" if common.contains_add(string): return string
def test_seen_attributes1(): x = Seen() assert isinstance(x.seenset, set) assert x.seenlist is None
def test_seen_equality9(): # empty sets, one has not-empty list assert not Seen(set()) == Seen(set(), [[T(0)]]) assert Seen(set()) != Seen(set(), [[T(0)]])
def test_seen_equality7(): # empty sets, one has empty list assert Seen(set(), []) == Seen(set()) assert not Seen(set(), []) != Seen(set())
def test_seen_equality5(): # set and list, not identical list contents assert not Seen({T(1)}, [T([0, 0]), T([1, 0])]) == Seen({T(1)}, [T([0, 1])]) assert Seen({T(1)}, [T([0, 0]), [T(1), T(0)]]) != Seen({T(1)}, [T([0, 0])])
def test_seen_equality3(): # set and list, identical contents assert Seen({T(1)}, [T([0, 0])]) == Seen({T(1)}, [T([0, 0])]) assert not Seen({T(1)}, [T([0, 0])]) != Seen({T(1)}, [T([0, 0])])
def test_seen_contains0(): x = Seen() assert T(1) not in x assert x == Seen(set()) assert T([0, 0]) not in x assert x == Seen(set())
def test_seen_repr0(): assert repr(Seen()) == 'iteration_utilities.Seen(set())' assert repr(Seen({T(1)})) == 'iteration_utilities.Seen({T(1)})' assert repr(Seen(set(), [])) == repr(Seen()) expected = 'iteration_utilities.Seen(set(), seenlist=[T(1)])' assert repr(Seen(set(), [T(1)])) == expected
def test_seen_failures3(): # seenlist must be a list with pytest.raises(TypeError) as exc: Seen({10, 20}, tuple([1, 2, 3])) assert '`seenlist`' in str(exc.value) and 'list' in str(exc.value)
def test_seen_new_None1(): # seenset=None is identical to no seenset assert Seen(None) == Seen()
def test_seen_failures1(): # too many arguments with pytest.raises(TypeError): Seen({10, 20}, [1, 2, 3], [1, 2, 3])
def test_seen_equality0(): assert Seen() == Seen() assert not Seen() != Seen()
def test_seen_containsadd_failure2(): # Failure when comparing the object to the objects in the list x = Seen(set(), [T(0)]) with pytest.raises(_hf.FailEqNoHash.EXC_TYP, match=_hf.FailEqNoHash.EXC_MSG): x.contains_add(_hf.FailEqNoHash())
def test_seen_containsadd_failure1(): # Failure (no TypeError) when trying to hash the value x = Seen({T(0)}) with pytest.raises(_hf.FailHash.EXC_TYP, match=_hf.FailHash.EXC_MSG): x.contains_add(_hf.FailHash())
def test_seen_repr1(): # check that even though it can't be immediately set that recursive # representations are catched s = Seen() s.contains_add([s]) assert repr(s) == 'iteration_utilities.Seen(set(), seenlist=[[...]])'
def test_seen_failures4(): # seen can only be compared to other seen's. with pytest.raises(TypeError, match='`Seen` instances can only compared to other ' '`Seen` instances'): Seen() == set()
def test_seen_equality2(): # only sets, not identical contents assert not Seen({T(1), T(2), T(3)}) == Seen({T(1), T(2)}) assert Seen({T(1), T(2), T(3)}) != Seen({T(1), T(2)})
def test_seen_failures2(): # seenset not a set with pytest.raises(TypeError) as exc: Seen(frozenset({10, 20})) assert '`seenset`' in str(exc.value) and 'set' in str(exc.value)
def test_seen_new_None2(): # seenlist=None is identical to no seenlist assert Seen(set(), None) == Seen(set())