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

Class TestNodeUnderflow

python/tests/test_bplus_tree.py:402–509  ·  view source on GitHub ↗

Test node underflow detection

Source from the content-addressed store, hash-verified

400
401
402class TestNodeUnderflow:
403 """Test node underflow detection"""
404
405 def test_leaf_underflow_detection(self):
406 """Test that leaf nodes correctly detect underflow"""
407 leaf = LeafNode(capacity=4) # min_keys = (4-1)//2 = 1
408
409 # Empty leaf is underfull
410 assert leaf.is_underfull()
411
412 # Single key is at minimum (not underfull)
413 leaf.insert(1, "one")
414 assert not leaf.is_underfull()
415
416 # Two keys is definitely not underfull
417 leaf.insert(2, "two")
418 assert not leaf.is_underfull()
419
420 # More keys is definitely not underfull
421 leaf.insert(3, "three")
422 assert not leaf.is_underfull()
423
424 def test_branch_underflow_detection(self):
425 """Test that branch nodes correctly detect underflow"""
426 branch = BranchNode(capacity=4) # min_keys = (4-1)//2 = 1
427
428 # Empty branch is underfull
429 assert branch.is_underfull()
430
431 # Single key is at minimum (not underfull)
432 branch.keys.append(5)
433 assert not branch.is_underfull()
434
435 # Two keys is definitely not underfull
436 branch.keys.append(10)
437 assert not branch.is_underfull()
438
439 # More keys is definitely not underfull
440 branch.keys.append(15)
441 assert not branch.is_underfull()
442
443 def test_underflow_after_deletion_creates_violation(self):
444 """Test that deleting keys can create underflow violations"""
445 tree = BPlusTreeMap(capacity=4)
446
447 # Create a tree with enough items to have branch nodes
448 for i in range(1, 10):
449 tree[i] = f"value_{i}"
450
451 # Delete many items to potentially create underflow
452 # (This test documents current behavior - underflow handling will be added later)
453 del tree[1]
454 del tree[2]
455 del tree[3]
456 del tree[4]
457
458 # Check if any nodes are underfull (they might be, which is expected for now)
459 has_underflow = self._tree_has_underflow(tree)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected