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