def test_skiplistset_boolean_value():
    s = SkipListSet()
    eq_(bool(s), False)
    s.add(1)
    eq_(bool(s), True)
    s.remove(1)
    eq_(bool(s), False)
def test_skiplistset_boolean_value():
    s = SkipListSet()
    eq_(bool(s), False)
    s.add(1)
    eq_(bool(s), True)
    s.remove(1)
    eq_(bool(s), False)
def test_general_skiplistset_behaviour():
    stuff = SkipListSet(capacity=1024)

    used_keys = set((0, ))

    for count in xrange(1000):
        eq_(len(stuff), count)

        items = tuple(stuff)
        if items:
            previous_key = items[0]
            for k in items[1:]:
                ok_(k > previous_key,
                    '%r should be greater than %r' % (k, previous_key))
                previous_key = k

        number = 0
        while number in used_keys:
            number = randint(0, 1000000)

        used_keys.add(number)

        ok_(number not in stuff)

        stuff.add(number)

        ok_(number in stuff)

    used_keys.remove(0)

    for key in set(used_keys):
        used_keys.remove(key)

        ok_(key in stuff)
        stuff.remove(key)
        ok_(key not in stuff)

        try:
            stuff.remove(key)
            assert False, 'Should have raised an exception'
        except KeyError:
            pass

        eq_(len(stuff), len(used_keys))
def test_general_skiplistset_behaviour():
    stuff = SkipListSet(capacity=1024)

    used_keys = set((0,))

    for count in xrange(1000):
        eq_(len(stuff), count)

        items = tuple(stuff)
        if items:
            previous_key = items[0]
            for k in items[1:]:
                ok_(k > previous_key, '%r should be greater than %r' % (k, previous_key))
                previous_key = k

        number = 0
        while number in used_keys:
            number = randint(0, 1000000)

        used_keys.add(number)

        ok_(number not in stuff)

        stuff.add(number)

        ok_(number in stuff)

    used_keys.remove(0)

    for key in set(used_keys):
        used_keys.remove(key)

        ok_(key in stuff)
        stuff.remove(key)
        ok_(key not in stuff)

        try:
            stuff.remove(key)
            assert False, 'Should have raised an exception'
        except KeyError:
            pass

        eq_(len(stuff), len(used_keys))