Exemplo n.º 1
0
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
Exemplo n.º 2
0
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])])
Exemplo n.º 3
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
Exemplo n.º 4
0
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
Exemplo n.º 7
0
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())
Exemplo n.º 8
0
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
Exemplo n.º 9
0
def test_seen_attributes1():
    x = Seen()
    assert isinstance(x.seenset, set)
    assert x.seenlist is None
Exemplo n.º 10
0
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)]])
Exemplo n.º 11
0
def test_seen_equality7():
    # empty sets, one has empty list
    assert Seen(set(), []) == Seen(set())
    assert not Seen(set(), []) != Seen(set())
Exemplo n.º 12
0
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])])
Exemplo n.º 13
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])])
Exemplo n.º 14
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())
Exemplo n.º 15
0
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
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
def test_seen_new_None1():
    # seenset=None is identical to no seenset
    assert Seen(None) == Seen()
Exemplo n.º 18
0
def test_seen_failures1():
    # too many arguments
    with pytest.raises(TypeError):
        Seen({10, 20}, [1, 2, 3], [1, 2, 3])
Exemplo n.º 19
0
def test_seen_equality0():
    assert Seen() == Seen()
    assert not Seen() != Seen()
Exemplo n.º 20
0
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())
Exemplo n.º 21
0
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())
Exemplo n.º 22
0
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=[[...]])'
Exemplo n.º 23
0
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()
Exemplo n.º 24
0
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)})
Exemplo n.º 25
0
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)
Exemplo n.º 26
0
def test_seen_new_None2():
    # seenlist=None is identical to no seenlist
    assert Seen(set(), None) == Seen(set())