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

Function test_branch_node_split_creates_new_level

rust/tests/bplus_tree.rs:631–714  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

629
630#[test]
631fn test_branch_node_split_creates_new_level() {
632 let mut tree = BPlusTreeMap::new(4).unwrap();
633
634 // Insert enough items to create a multi-level tree structure
635 // This should eventually cause branch node splits
636 let mut items_inserted = 0;
637 let initial_leaf_count = tree.leaf_count();
638
639 // Insert items until we have a significant tree structure
640 // With capacity 4, we need enough items to fill multiple branch nodes
641 for i in 1..=25 {
642 tree.insert(i, format!("value_{}", i));
643 items_inserted += 1;
644
645 // Verify invariants are maintained after each insertion
646 assert!(
647 tree.check_invariants(),
648 "Tree invariants should be maintained after inserting item {}",
649 i
650 );
651 }
652
653 // Verify we have more leaf nodes than we started with
654 let final_leaf_count = tree.leaf_count();
655 assert!(
656 final_leaf_count > initial_leaf_count,
657 "Should have more leaf nodes after inserting {} items. Initial: {}, Final: {}",
658 items_inserted,
659 initial_leaf_count,
660 final_leaf_count
661 );
662
663 // Verify we have a branch root (not a leaf root)
664 assert!(
665 !tree.is_leaf_root(),
666 "Tree should have a branch root after inserting {} items",
667 items_inserted
668 );
669
670 // Verify all items are still accessible
671 for i in 1..=25 {
672 assert_eq!(
673 tree.get(&i),
674 Some(&format!("value_{}", i)),
675 "Item {} should be accessible in multi-level tree",
676 i
677 );
678 }
679
680 // Verify tree structure and size
681 assert_eq!(tree.len(), 25, "Tree should have 25 items");
682
683 // Verify range queries work correctly across the complex structure
684 let range: Vec<_> = tree.items_range(Some(&1), Some(&26)).collect();
685 assert_eq!(range.len(), 25, "Range query should return all 25 items");
686
687 // Verify items are in sorted order
688 for i in 0..range.len() - 1 {

Callers

nothing calls this directly

Calls 4

items_rangeMethod · 0.80
leaf_countMethod · 0.45
insertMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected