Test the specific case that was creating single-child parents
()
| 50 | |
| 51 | |
| 52 | def test_specific_problematic_case(): |
| 53 | """Test the specific case that was creating single-child parents""" |
| 54 | tree = BPlusTreeMap(capacity=4) # Minimum viable capacity |
| 55 | |
| 56 | # Build a larger case to stress test the deletion logic |
| 57 | for i in range(16): |
| 58 | tree[i] = f"value_{i}" |
| 59 | |
| 60 | print("Built tree with items 0-15") |
| 61 | assert check_invariants(tree), "Initial tree should be valid" |
| 62 | |
| 63 | # Delete in a problematic order that stresses merge/redistribute logic |
| 64 | problematic_deletes = [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14] |
| 65 | |
| 66 | for key in problematic_deletes: |
| 67 | print(f"\nDeleting {key}...") |
| 68 | del tree[key] |
| 69 | |
| 70 | invariants_ok = check_invariants(tree) |
| 71 | print(f"Invariants OK: {invariants_ok}") |
| 72 | |
| 73 | if not invariants_ok: |
| 74 | print("Structure after violation:") |
| 75 | _print_structure(tree.root, 0) |
| 76 | assert False, f"Invariants violated after deleting {key}" |
| 77 | |
| 78 | print("✅ Problematic case now maintains invariants!") |
| 79 | |
| 80 | |
| 81 | def test_merge_vs_redistribute(): |
no test coverage detected