Example #1
0
def test_collision():
    HASH = 13465345
    mp = PersistentTreeSet()
    mp = mp.add(HashCollision("hello", HASH))
    mp = mp.add(HashCollision("answer", HASH))
    assert HashCollision("hello", HASH) in mp
    assert HashCollision("answer", HASH) in mp
Example #2
0
def test_collision():
    HASH = 13465345
    mp = PersistentTreeSet()
    mp = mp.add(HashCollision("hello", HASH))
    mp = mp.add(HashCollision("answer", HASH))
    assert HashCollision("hello", HASH) in mp
    assert HashCollision("answer", HASH) in mp
Example #3
0
def test_and():
    some = random_set(1000)
    some.update(['a', 'b', 'c'])
    other = random_set(1000)
    other.update(set(['a', 'c', 'd']))
    
    df = PersistentTreeSet.from_set(some) & PersistentTreeSet.from_set(other)
    
    assert set(df) == some & other
Example #4
0
def test_and():
    some = random_set(1000)
    some.update(['a', 'b', 'c'])
    other = random_set(1000)
    other.update(set(['a', 'c', 'd']))

    df = PersistentTreeSet.from_set(some) & PersistentTreeSet.from_set(other)

    assert set(df) == some & other
Example #5
0
def test_persistence():
    mp = PersistentTreeSet()
    mp1 = mp.add('a')
    assert 'a' in mp1
    mp2 = mp1.add('b')
    assert 'a' in mp2
    assert 'b' in mp2
    assert 'b' not in mp1
    mp3 = mp2.without('a')
    assert 'b' in mp3
    assert 'a' not in mp3
Example #6
0
def test_persistence():
    mp = PersistentTreeSet()
    mp1 = mp.add('a')
    assert 'a' in mp1
    mp2 = mp1.add('b')
    assert 'a' in mp2
    assert 'b' in mp2
    assert 'b' not in mp1
    mp3 = mp2.without('a')
    assert 'b' in mp3
    assert 'a' not in mp3
Example #7
0
def test_transient():
    mp = PersistentTreeSet.from_set(set(['foo']))
    mp2 = mp.transient()
    mp3 = mp2.add('bar')
    assert mp2 is mp3
    assert 'foo' in mp2
    assert 'bar' in mp2
    assert 'foo' in mp3
    assert 'bar' in mp3
    
    mp4 = mp3.persistent()
    mp5 = mp4.add('baz')
    assert 'baz' not in mp2
    assert 'baz' not in mp3
    assert 'baz' not in mp4
    assert 'baz' in mp5
    assert mp5 is not mp4
Example #8
0
def test_transient():
    mp = PersistentTreeSet.from_set(set(['foo']))
    mp2 = mp.transient()
    mp3 = mp2.add('bar')
    assert mp2 is mp3
    assert 'foo' in mp2
    assert 'bar' in mp2
    assert 'foo' in mp3
    assert 'bar' in mp3

    mp4 = mp3.persistent()
    mp5 = mp4.add('baz')
    assert 'baz' not in mp2
    assert 'baz' not in mp3
    assert 'baz' not in mp4
    assert 'baz' in mp5
    assert mp5 is not mp4
Example #9
0
def test_iteration():
    st = random_set(1000)
    mp = PersistentTreeSet.from_set(st)
    assert set(mp) == st
Example #10
0
def test_fromset():
    st = random_set(1000)
    mp = PersistentTreeSet.from_set(st)
    for elem in st:
        assert elem in mp
Example #11
0
def test_iteration():
    st = random_set(1000)
    mp = PersistentTreeSet.from_set(st)
    assert set(mp) == st
Example #12
0
def test_fromset():
    st = random_set(1000)
    mp = PersistentTreeSet.from_set(st)
    for elem in st:
        assert elem in mp