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

Function test_split_then_add

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

Source from the content-addressed store, hash-verified

137
138#[test]
139fn test_split_then_add() {
140 let mut tree = create_tree_4();
141 // With capacity=4, need more items to force multiple splits
142 tree.insert(1, "one".to_string());
143 tree.insert(2, "two".to_string());
144 tree.insert(3, "three".to_string());
145 tree.insert(4, "four".to_string());
146 tree.insert(5, "five".to_string());
147 tree.insert(6, "six".to_string());
148 tree.insert(7, "seven".to_string());
149 tree.insert(8, "eight".to_string());
150
151 // Check correctness via invariants instead of exact structure
152 assert_invariants(&tree, "split then add");
153 assert_eq!(tree.len(), 8);
154 assert_eq!(tree.get(&1), Some(&"one".to_string()));
155 assert_eq!(tree.get(&2), Some(&"two".to_string()));
156 assert_eq!(tree.get(&3), Some(&"three".to_string()));
157 assert_eq!(tree.get(&4), Some(&"four".to_string()));
158 assert_eq!(tree.get(&5), Some(&"five".to_string()));
159 assert_eq!(tree.get(&6), Some(&"six".to_string()));
160 assert_eq!(tree.get(&7), Some(&"seven".to_string()));
161 assert_eq!(tree.get(&8), Some(&"eight".to_string()));
162
163 // The simpler implementation may create more leaves, but that's OK
164 // as long as invariants hold
165 assert!(tree.leaf_count() >= 2); // At minimum need 2 leaves for 8 items with capacity 4
166}
167
168#[test]
169fn test_many_insertions_maintain_invariants() {

Callers

nothing calls this directly

Calls 3

create_tree_4Function · 0.85
assert_invariantsFunction · 0.85
insertMethod · 0.45

Tested by

no test coverage detected