Test suite to ensure no segfaults occur.
| 20 | |
| 21 | |
| 22 | class TestNoSegfaults: |
| 23 | """Test suite to ensure no segfaults occur.""" |
| 24 | |
| 25 | def test_large_sequential_insert(self): |
| 26 | """Test large sequential insertions that previously caused segfaults.""" |
| 27 | if not HAS_C_EXTENSION: |
| 28 | pytest.skip("C extension not available") |
| 29 | |
| 30 | tree = bplustree_c.BPlusTree(capacity=128) |
| 31 | |
| 32 | # Insert 10,000 items sequentially |
| 33 | for i in range(10000): |
| 34 | tree[i] = i * 2 |
| 35 | |
| 36 | # Verify tree is still functional every 1000 items |
| 37 | if i % 1000 == 0: |
| 38 | assert len(tree) == i + 1, f"Tree size incorrect at {i}" |
| 39 | assert tree[i] == i * 2, f"Value incorrect at {i}" |
| 40 | |
| 41 | print(f"✓ Successfully inserted 10,000 sequential items") |
| 42 | |
| 43 | def test_large_random_insert(self): |
| 44 | """Test large random insertions.""" |
| 45 | if not HAS_C_EXTENSION: |
| 46 | pytest.skip("C extension not available") |
| 47 | |
| 48 | tree = bplustree_c.BPlusTree(capacity=128) |
| 49 | |
| 50 | # Generate random keys |
| 51 | keys = list(range(5000)) |
| 52 | random.shuffle(keys) |
| 53 | |
| 54 | # Insert all keys |
| 55 | for i, key in enumerate(keys): |
| 56 | tree[key] = key * 2 |
| 57 | |
| 58 | # Verify periodically |
| 59 | if i % 500 == 0: |
| 60 | assert len(tree) == i + 1, f"Tree size incorrect at insertion {i}" |
| 61 | |
| 62 | # Verify all keys are present |
| 63 | for key in keys: |
| 64 | assert tree[key] == key * 2, f"Key {key} not found or has wrong value" |
| 65 | |
| 66 | print(f"✓ Successfully inserted 5,000 random items") |
| 67 | |
| 68 | def test_mixed_operations_large(self): |
| 69 | """Test mixed insert/lookup/delete operations on large dataset.""" |
| 70 | if not HAS_C_EXTENSION: |
| 71 | pytest.skip("C extension not available") |
| 72 | |
| 73 | tree = bplustree_c.BPlusTree(capacity=64) |
| 74 | |
| 75 | # Phase 1: Insert large dataset |
| 76 | keys = list(range(3000)) |
| 77 | random.shuffle(keys) |
| 78 | |
| 79 | for key in keys: |
no outgoing calls