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)
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)
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
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
def test_literalish_works(): assert s(1, 2) == pset([1, 2])
def test_s_constructor(): container = s() assert len(container) == 0 container = s(0, "1", 2, 6, 10) assert len(container) == 5
def test_update_no_elements(): s1 = s(1, 2) assert s1.update([]) is s1
def test_update(): assert s(1, 2, 3).update([3, 4, 4, 5]) == s(1, 2, 3, 4, 5)
def test_supports_weakref(): import weakref weakref.ref(s(1))
def test_pickling_non_empty_map(): assert pickle.loads(pickle.dumps(s(1, 2), -1)) == s(1, 2)
def test_discard(): s1 = s(1, 2, 3) assert s1.discard(3) == s(1, 2) assert s1.discard(4) == s1
def test_copy_returns_reference_to_self(): s1 = s(10) assert s1.copy() is s1
def test_evolver_len(): x = s(1, 2, 3) e = x.evolver() assert len(e) == 3
def test_evolver_no_update_produces_same_pset(): x = s(1, 2, 3) e = x.evolver() assert e.persistent() is x
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))
def test_pickling_empty_set(): assert pickle.loads(pickle.dumps(s(), -1)) == s()
def test_empty_truthiness(): assert s(1) assert not s()
def test_remove_when_not_present(): s1 = s(1, 2, 3) with pytest.raises(KeyError): s1.remove(4)