Test basic B+ tree operations
| 14 | |
| 15 | |
| 16 | class TestBasicOperations: |
| 17 | """Test basic B+ tree operations""" |
| 18 | |
| 19 | def test_create_empty_tree(self): |
| 20 | """Test creating an empty tree""" |
| 21 | tree = BPlusTreeMap(capacity=4) |
| 22 | assert len(tree) == 0 |
| 23 | assert not tree # Should be falsy when empty |
| 24 | assert check_invariants(tree) |
| 25 | |
| 26 | def test_insert_and_get_single_item(self): |
| 27 | """Test inserting and retrieving a single item""" |
| 28 | tree = BPlusTreeMap(capacity=4) |
| 29 | tree[1] = "one" |
| 30 | |
| 31 | assert len(tree) == 1 |
| 32 | assert tree # Should be truthy when not empty |
| 33 | assert tree[1] == "one" |
| 34 | assert tree.get(1) == "one" |
| 35 | assert check_invariants(tree) |
| 36 | |
| 37 | def test_insert_multiple_items(self): |
| 38 | """Test inserting multiple items""" |
| 39 | tree = BPlusTreeMap(capacity=4) |
| 40 | tree[1] = "one" |
| 41 | tree[2] = "two" |
| 42 | tree[3] = "three" |
| 43 | |
| 44 | assert len(tree) == 3 |
| 45 | assert tree[1] == "one" |
| 46 | assert tree[2] == "two" |
| 47 | assert tree[3] == "three" |
| 48 | assert check_invariants(tree) |
| 49 | |
| 50 | def test_update_existing_key(self): |
| 51 | """Test updating an existing key""" |
| 52 | tree = BPlusTreeMap(capacity=4) |
| 53 | tree[1] = "one" |
| 54 | tree[1] = "ONE" |
| 55 | |
| 56 | assert len(tree) == 1 # Size shouldn't change |
| 57 | assert tree[1] == "ONE" |
| 58 | assert check_invariants(tree) |
| 59 | |
| 60 | def test_contains_operator(self): |
| 61 | """Test the 'in' operator""" |
| 62 | tree = BPlusTreeMap(capacity=4) |
| 63 | tree[1] = "one" |
| 64 | tree[2] = "two" |
| 65 | |
| 66 | assert 1 in tree |
| 67 | assert 2 in tree |
| 68 | assert 3 not in tree |
| 69 | assert check_invariants(tree) |
| 70 | |
| 71 | def test_get_with_default(self): |
| 72 | """Test get() with default value""" |
| 73 | tree = BPlusTreeMap(capacity=4) |
nothing calls this directly
no outgoing calls
no test coverage detected