Пример #1
0
 def get(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.get(2) == True
     assert bt.get(-1) == None
     assert bt.get(-1, 5) == 5
Пример #2
0
 def test_delete_case_2c(self):
     bt = BTree(BNode)
     for j in 'abcdefghi':
         bt.add(j)
     assert bt.root.items == [('d', True)]
     del bt['d']
     assert len(bt) == bt.root.get_count()
Пример #3
0
 def get(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.get(2) == True
     assert bt.get(-1) == None
     assert bt.get(-1, 5) == 5
Пример #4
0
 def find_extremes(self):
     bt = BTree()
     raises(AssertionError, bt.get_min_item)
     raises(AssertionError, bt.get_max_item)
     for j in range(100):
         bt.add(j)
     assert bt.get_min_item() == (0, True)
     assert bt.get_max_item() == (99, True)
Пример #5
0
 def clear(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.has_key(2)
     bt.clear()
     assert not bt.has_key(2)
     assert bt.keys() == []
Пример #6
0
 def clear(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.has_key(2)
     bt.clear()
     assert not bt.has_key(2)
     assert bt.keys() == []
Пример #7
0
 def find_extremes(self):
     bt = BTree()
     raises(AssertionError, bt.get_min_item)
     raises(AssertionError, bt.get_max_item)
     for j in range(100):
         bt.add(j)
     assert bt.get_min_item() == (0, True)
     assert bt.get_max_item() == (99, True)
Пример #8
0
 def search(self):
     bt = BTree(BNode)
     for j in range(100):
         bt.add(j)
     assert bt[1] == True
     try:
         assert bt[-1]
     except KeyError:
         pass
Пример #9
0
 def items_from(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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)))
         assert (list([(x, y) for (x, y) in bt.items() if x > cutoff
                       ]) == list(bt.items_from(cutoff, closed=False)))
Пример #10
0
 def iter(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(bt) == list(bt.iterkeys())
     assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
     assert list(bt.iterkeys()) == list(bt.keys())
     assert list(bt.itervalues()) == list(bt.values())
     assert list(bt.iteritems()) == list(bt.items())
Пример #11
0
 def iter(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(bt) == list(bt.iterkeys())
     assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
     assert list(bt.iterkeys()) == list(bt.keys())
     assert list(bt.itervalues()) == list(bt.values())
     assert list(bt.iteritems()) == list(bt.items())
Пример #12
0
 def items_from(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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)))
         assert (list([(x, y) for (x, y) in bt.items() if x > cutoff]) ==
                 list(bt.items_from(cutoff, closed=False)))
Пример #13
0
 def search(self):
     bt = BTree(BNode)
     for j in range(100):
         bt.add(j)
     assert bt[1] == True
     try:
         assert bt[-1]
     except KeyError:
         pass
Пример #14
0
 def _delete_case_3(self):
     bt = BTree(BNode)
     for j in range(100):
         bt.add(j)
     assert bt.root.items == [(31, True), (63, True)]
     assert [n.items for n in bt.root.nodes] == [[(15, True)], [(47, True)],
                                                 [(79, True)]]
     assert [[n.items for n in node.nodes]
             for node in bt.root.nodes] == [[[(7, True)], [(23, True)]],
                                            [[(39, True)], [(55, True)]],
                                            [[(71, True)], [(87, True)]]]
     return bt
Пример #15
0
 def items_backward_from(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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)
         expect = list(
             reversed([(x, y) for (x, y) in bt.items() if x <= cutoff]))
         got = list(bt.items_backward_from(cutoff, closed=True))
         assert expect == got, (cutoff, expect, got)
Пример #16
0
 def items_backward_from(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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)
         expect = list(reversed([(x, y) for (x, y) in bt.items()
                                 if x <= cutoff]))
         got = list(bt.items_backward_from(cutoff, closed=True))
         assert expect == got, (cutoff, expect, got)
Пример #17
0
 def _delete_case_3(self):
     bt = BTree(BNode)
     for j in range(100):
         bt.add(j)
     assert bt.root.items == [(31, True), (63, True)]
     assert [n.items for n in bt.root.nodes] == [
         [(15, True)], [(47, True)], [(79, True)]]
     assert [[n.items for n in node.nodes]
             for node in bt.root.nodes] == [
         [[(7, True)], [(23, True)]],
         [[(39, True)], [(55, True)]],
         [[(71, True)], [(87, True)]]]
     return bt
Пример #18
0
 def test_iter(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     if hasattr(bt, 'iterkeys'):
         assert list(bt) == list(bt.iterkeys())
         assert list(bt.iteritems()) == list(zip(bt, bt.itervalues()))
         assert list(bt.iterkeys()) == list(bt.keys())
         assert list(bt.itervalues()) == list(bt.values())
         assert list(bt.iteritems()) == list(bt.items())
     else:
         assert list(bt) == list(bt.keys())
         assert list(bt.items()) == list(zip(bt, bt.values()))
Пример #19
0
 def items_range(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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([(x, y) for (x, y) in bt.items()
                     if lo < x < hi])
         got = list(bt.items_range(lo, hi, closed_start=False))
         assert expect == got, (lo, hi, expect, got)
         expect = list([(x, y) for (x, y) in bt.items()
                     if lo < x <= hi])
         got = list(bt.items_range(
             lo, hi, closed_start=False, closed_end=True))
         assert expect == got, (lo, hi, expect, got)
         expect = list([(x, y) for (x, y) in bt.items()
                     if lo <= x <= hi])
         got = list(bt.items_range(
             lo, hi, closed_start=True, closed_end=True))
         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)
         expect = list(reversed([(x, y) for (x, y) in bt.items()
                     if lo <= x <= hi]))
         got = list(bt.items_range(hi, lo, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
         expect = list(reversed([(x, y) for (x, y) in bt.items()
                     if lo <= x < hi]))
         got = list(bt.items_range(
             hi, lo, closed_start=False, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
         expect = list(reversed([(x, y) for (x, y) in bt.items()
                     if lo < x < hi]))
         got = list(bt.items_range(
             hi, lo, closed_start=False, closed_end=False))
         assert expect == got, (hi, lo, expect, got)
         expect = list(reversed([(x, y) for (x, y) in bt.items()
                     if lo <= x <= hi]))
         got = list(bt.items_range(hi, lo, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
Пример #20
0
 def items_range(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     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([(x, y) for (x, y) in bt.items() if lo < x < hi])
         got = list(bt.items_range(lo, hi, closed_start=False))
         assert expect == got, (lo, hi, expect, got)
         expect = list([(x, y) for (x, y) in bt.items() if lo < x <= hi])
         got = list(
             bt.items_range(lo, hi, closed_start=False, closed_end=True))
         assert expect == got, (lo, hi, expect, got)
         expect = list([(x, y) for (x, y) in bt.items() if lo <= x <= hi])
         got = list(
             bt.items_range(lo, hi, closed_start=True, closed_end=True))
         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)
         expect = list(
             reversed([(x, y) for (x, y) in bt.items() if lo <= x <= hi]))
         got = list(bt.items_range(hi, lo, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
         expect = list(
             reversed([(x, y) for (x, y) in bt.items() if lo <= x < hi]))
         got = list(
             bt.items_range(hi, lo, closed_start=False, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
         expect = list(
             reversed([(x, y) for (x, y) in bt.items() if lo < x < hi]))
         got = list(
             bt.items_range(hi, lo, closed_start=False, closed_end=False))
         assert expect == got, (hi, lo, expect, got)
         expect = list(
             reversed([(x, y) for (x, y) in bt.items() if lo <= x <= hi]))
         got = list(bt.items_range(hi, lo, closed_end=True))
         assert expect == got, (hi, lo, expect, got)
Пример #21
0
 def contains(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert 2 in bt
     assert -1 not in bt
Пример #22
0
 def delete_case_2a(self):
     bt = BTree(BNode)
     for j in 'jklmoab':
         bt.add(j)
     del bt['k']
Пример #23
0
 def delete_case_2a(self):
     bt = BTree(BNode)
     for j in 'jklmoab':
         bt.add(j)
     del bt['k']
Пример #24
0
 def has_key(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.has_key(2)
     assert not bt.has_key(-1)
Пример #25
0
 def reversed(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(reversed(bt)) == list(reversed(list(bt)))
Пример #26
0
 def contains(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert 2 in bt
     assert -1 not in bt
Пример #27
0
 def delete_case_2c(self):
     bt = BTree(BNode)
     for j in 'abcdefghi':
         bt.add(j)
     assert bt.root.items == [('d', True)]
     del bt['d']
Пример #28
0
 def items_backward(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(reversed(bt.items())) == list(bt.items_backward())
Пример #29
0
 def reversed(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(reversed(bt)) == list(reversed(list(bt)))
Пример #30
0
 def delete_case_2c(self):
     bt = BTree(BNode)
     for j in 'abcdefghi':
         bt.add(j)
     assert bt.root.items == [('d', True)]
     del bt['d']
Пример #31
0
 def items_backward(self):
     bt = BTree()
     for j in range(100):
         bt.add(j)
     assert list(reversed(bt.items())) == list(bt.items_backward())
Пример #32
0
 def test_delete_case_2a(self):
     bt = BTree(BNode)
     for j in 'jklmoab':
         bt.add(j)
     del bt['k']
     assert len(bt) == bt.root.get_count()
Пример #33
0
 def has_key(self):
     bt = BTree()
     for j in range(10):
         bt.add(j)
     assert bt.has_key(2)
     assert not bt.has_key(-1)