Example #1
0
def test_contains(min_items=2, max_items=1000):
    items = KeypoolDict()

    for i in xrange(0, MAX_ITER):
        rand = random.randint(min_items, max_items)
        keys = [items.setitem(i) for i in xrange(0, rand)]

        assert all([key in items for key in keys])
Example #2
0
def test_quick_allocate():
    items = KeypoolDict()
    min = 2
    max = 10

    for i in xrange(0, MAX_ITER):
        rand = random.randint(min, max)
        keys = [items.setitem(i) for i in xrange(0, rand)]
        assert_unique(keys)
Example #3
0
def test_keygen():
    pool = Keypool(start=0)
    dict = KeypoolDict()

    for i in xrange(0, MAX_ITER):
        k1 = pool.next()
        k2 = dict.next()
        print k1
        print k2
Example #4
0
def test_no_intermediate_assignment():
    items = KeypoolDict()
    items[items.next()] = "a"
    items[items.next()] = "b"
    items[items.next()] = "c"

    del items[0]

    assert 0 not in items
    assert 1 in items
    assert 2 in items

    items[items.next()] = "d"

    assert 0 in items
    assert items[0] == "d"
Example #5
0
def test_reuse(min_items=2, max_items=1000):
    items = KeypoolDict()

    for i in xrange(0, MAX_ITER):
        rand = random.randint(min_items, max_items)
        keys = [items.setitem(i) for i in xrange(0, rand)]

        # No keys are identical
        assert_unique(keys)

        # Delete all the items
        [delitem(items, key) for key in items.keys()]

        # The old keys are now reused
        keys2 = [items.setitem(i) for i in xrange(0, rand)]

        assert keys == keys2
        assert_unique(keys)

        [delitem(items, key) for key in items.keys()]