Beispiel #1
0
def test_evolver_simple_remove():
    x = s(1, 2, 3)
    e = x.evolver()
    e.remove(2)

    x2 = e.persistent()
    assert x2 == s(1, 3)
    assert x == s(1, 2, 3)
Beispiel #2
0
def test_evolver_simple_add():
    x = s(1, 2, 3)
    e = x.evolver()
    assert not e.is_dirty()

    e.add(4)
    assert e.is_dirty()

    x2 = e.persistent()
    assert not e.is_dirty()
    assert x2 == s(1, 2, 3, 4)
    assert x == s(1, 2, 3)
Beispiel #3
0
def test_supports_set_comparisons():
    s1 = s(1, 2, 3)
    s3 = s(1, 2)
    s4 = s(1, 2, 3)

    assert s(1, 2, 3, 3, 5) == s(1, 2, 3, 5)
    assert s1 != s3

    assert s3 < s1
    assert s3 <= s1
    assert s3 <= s4

    assert s1 > s3
    assert s1 >= s3
    assert s4 >= s3
Beispiel #4
0
def test_supports_set_operations():
    s1 = pset([1, 2, 3])
    s2 = pset([3, 4, 5])

    assert s1 | s2 == s(1, 2, 3, 4, 5)
    assert s1.union(s2) == s1 | s2

    assert s1 & s2 == s(3)
    assert s1.intersection(s2) == s1 & s2

    assert s1 - s2 == s(1, 2)
    assert s1.difference(s2) == s1 - s2

    assert s1 ^ s2 == s(1, 2, 4, 5)
    assert s1.symmetric_difference(s2) == s1 ^ s2
Beispiel #5
0
def test_literalish_works():
    assert s(1, 2) == pset([1, 2])
Beispiel #6
0
def test_s_constructor():
    container = s()
    assert len(container) == 0

    container = s(0, "1", 2, 6, 10)
    assert len(container) == 5
Beispiel #7
0
def test_update_no_elements():
    s1 = s(1, 2)
    assert s1.update([]) is s1
Beispiel #8
0
def test_update():
    assert s(1, 2, 3).update([3, 4, 4, 5]) == s(1, 2, 3, 4, 5)
Beispiel #9
0
def test_supports_weakref():
    import weakref

    weakref.ref(s(1))
Beispiel #10
0
def test_pickling_non_empty_map():
    assert pickle.loads(pickle.dumps(s(1, 2), -1)) == s(1, 2)
Beispiel #11
0
def test_discard():
    s1 = s(1, 2, 3)
    assert s1.discard(3) == s(1, 2)
    assert s1.discard(4) == s1
Beispiel #12
0
def test_copy_returns_reference_to_self():
    s1 = s(10)
    assert s1.copy() is s1
Beispiel #13
0
def test_evolver_len():
    x = s(1, 2, 3)
    e = x.evolver()
    assert len(e) == 3
Beispiel #14
0
def test_evolver_no_update_produces_same_pset():
    x = s(1, 2, 3)
    e = x.evolver()
    assert e.persistent() is x
Beispiel #15
0
def test_supports_hash():
    # pyrpds.pvector is order-agnostic
    # assert hash(s(1, 2)) == hash(s(1, 2))
    assert hash(s(1)) == hash(s(1))
Beispiel #16
0
def test_pickling_empty_set():
    assert pickle.loads(pickle.dumps(s(), -1)) == s()
Beispiel #17
0
def test_empty_truthiness():
    assert s(1)
    assert not s()
Beispiel #18
0
def test_remove_when_not_present():
    s1 = s(1, 2, 3)
    with pytest.raises(KeyError):
        s1.remove(4)