MCPcopy Create free account
hub / github.com/KentBeck/BPlusTree3 / TestBPlusTreeIterator

Class TestBPlusTreeIterator

python/tests/test_iterator.py:7–77  ·  view source on GitHub ↗

Test cases for B+ tree iteration

Source from the content-addressed store, hash-verified

5
6
7class TestBPlusTreeIterator:
8 """Test cases for B+ tree iteration"""
9
10 def test_iterate_empty_tree(self):
11 """Test iterating over an empty tree"""
12 tree = BPlusTreeMap(capacity=4)
13 items = list(tree.items())
14 assert items == []
15
16 def test_iterate_single_item(self):
17 """Test iterating over a tree with one item"""
18 tree = BPlusTreeMap(capacity=4)
19 tree[5] = "value5"
20
21 items = list(tree.items())
22 assert items == [(5, "value5")]
23
24 def test_iterate_multiple_items_single_leaf(self):
25 """Test iterating over multiple items in a single leaf"""
26 tree = BPlusTreeMap(capacity=4)
27 tree[1] = "value1"
28 tree[3] = "value3"
29 tree[2] = "value2"
30 tree[4] = "value4"
31
32 items = list(tree.items())
33 assert items == [(1, "value1"), (2, "value2"), (3, "value3"), (4, "value4")]
34
35 def test_iterate_multiple_leaves(self):
36 """Test iterating across multiple leaves"""
37 tree = BPlusTreeMap(capacity=4)
38 # Insert enough to create multiple leaves
39 for i in range(1, 10):
40 tree[i] = f"value{i}"
41
42 items = list(tree.items())
43 expected = [(i, f"value{i}") for i in range(1, 10)]
44 assert items == expected
45
46 def test_iterate_large_tree(self):
47 """Test iterating over a large tree"""
48 tree = BPlusTreeMap(capacity=4)
49 n = 100
50 for i in range(n):
51 tree[i] = f"value{i}"
52
53 items = list(tree.items())
54 assert len(items) == n
55 assert items[0] == (0, "value0")
56 assert items[-1] == (99, "value99")
57 # Check ordering
58 for i in range(1, n):
59 assert items[i][0] > items[i - 1][0]
60
61 def test_keys_iterator(self):
62 """Test iterating over just keys"""
63 tree = BPlusTreeMap(capacity=4)
64 for i in [5, 2, 8, 1, 9, 3]:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected