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

Class TestRemoval

python/tests/test_bplus_tree.py:250–399  ·  view source on GitHub ↗

Test B+ tree removal operations

Source from the content-addressed store, hash-verified

248
249
250class TestRemoval:
251 """Test B+ tree removal operations"""
252
253 def test_remove_single_item_from_leaf_root(self):
254 """Test removing a single item when root is a leaf"""
255 tree = BPlusTreeMap(capacity=4)
256 tree[1] = "one"
257
258 # Remove the item
259 del tree[1]
260
261 # Tree should be empty
262 assert len(tree) == 0
263 assert 1 not in tree
264 assert check_invariants(tree)
265
266 # Should raise KeyError when trying to get removed item
267 with pytest.raises(KeyError):
268 _ = tree[1]
269
270 def test_remove_multiple_items_from_leaf_root(self):
271 """Test removing multiple items when root is a leaf"""
272 tree = BPlusTreeMap(capacity=4)
273 tree[1] = "one"
274 tree[2] = "two"
275 tree[3] = "three"
276
277 # Remove items
278 del tree[2]
279
280 # Check state after first removal
281 assert len(tree) == 2
282 assert 1 in tree
283 assert 2 not in tree
284 assert 3 in tree
285 assert tree[1] == "one"
286 assert tree[3] == "three"
287 assert check_invariants(tree)
288
289 # Remove another item
290 del tree[1]
291
292 # Check state after second removal
293 assert len(tree) == 1
294 assert 1 not in tree
295 assert 3 in tree
296 assert tree[3] == "three"
297 assert check_invariants(tree)
298
299 # Remove last item
300 del tree[3]
301
302 # Tree should be empty
303 assert len(tree) == 0
304 assert check_invariants(tree)
305
306 def test_remove_nonexistent_key_raises_error(self):
307 """Test that removing a non-existent key raises KeyError"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected