def test_items_range(self): bt = BTree() map(bt.add, range(100)) lo = 0 hi = 40 for lo, hi in [(-1,10), (3, 9), (30, 200), (-10, 200)]: expect = list([(x, y) for (x, y) in bt.items() if lo <= x < hi]) got = list(bt.items_range(lo, hi)) assert expect == got, (lo, hi, expect, got) expect = list(reversed([(x, y) for (x, y) in bt.items() if lo < x <= hi])) got = list(bt.items_range(hi, lo)) assert expect == got, (hi, lo, expect, got)
def test_slow(self): bt = BTree() print 'bt = BTree()' d = {} number = 0 limit = 10000 for k in xrange(limit*10): number = randint(0, limit) if number in bt: assert number in d if randint(0, 1) == 1: del bt[number] del d[number] print 'del bt[%s]' % number else: if number in d: print number print number in bt print number in d assert number not in d bt[number] = 1 d[number] = 1 print 'bt[%s] = 1' % number if k % limit == 0: d_items = d.items() d_items.sort() assert d_items == bt.items() assert len(d_items) == len(bt)
def test_items_backward_from(self): bt = BTree() map(bt.add, range(100)) for cutoff in (-1, 1, 50.1, 100, 102): expect = list(reversed([(x, y) for (x, y) in bt.items() if x < cutoff])) got = list(bt.items_backward_from(cutoff)) assert expect == got, (cutoff, expect, got)
def test_iter(self): bt = BTree() map(bt.add, range(100)) assert list(bt) == list(bt.iterkeys()) assert list(bt.iteritems()) == zip(bt, bt.itervalues()) assert list(bt.iterkeys()) == bt.keys() assert list(bt.itervalues()) == bt.values() assert list(bt.iteritems()) == bt.items()
def test_items_from(self): bt = BTree() map(bt.add, range(100)) for cutoff in (-1, 1, 50.1, 100, 102): assert (list([(x, y) for (x, y) in bt.items() if x >= cutoff]) == list(bt.items_from(cutoff)))
def test_items_backward(self): bt = BTree() map(bt.add, range(100)) assert list(reversed(bt.items())) == list(bt.items_backward())