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

Class TestDictionaryAPI

python/tests/test_dictionary_api.py:25–330  ·  view source on GitHub ↗

Test all dictionary-like methods of BPlusTreeMap.

Source from the content-addressed store, hash-verified

23
24
25class TestDictionaryAPI:
26 """Test all dictionary-like methods of BPlusTreeMap."""
27
28 def setup_method(self):
29 """Set up test fixtures before each test method."""
30 self.tree = BPlusTreeMap(capacity=4)
31 # Add some initial data
32 for i in range(10):
33 self.tree[i] = f"value_{i}"
34
35 def test_clear(self):
36 """Test the clear() method."""
37 # Verify tree has data
38 assert len(self.tree) == 10
39 assert 5 in self.tree
40
41 # Clear the tree
42 self.tree.clear()
43
44 # Verify tree is empty
45 assert len(self.tree) == 0
46 assert 5 not in self.tree
47 assert bool(self.tree) == False
48
49 # Verify we can still add data after clearing
50 self.tree[100] = "new_value"
51 assert len(self.tree) == 1
52 assert self.tree[100] == "new_value"
53
54 def test_get_with_default(self):
55 """Test the get() method with default values."""
56 # Test existing key
57 assert self.tree.get(5) == "value_5"
58 assert self.tree.get(5, "default") == "value_5"
59
60 # Test non-existing key with default
61 assert self.tree.get(100) is None
62 assert self.tree.get(100, "default") == "default"
63 assert self.tree.get(100, 42) == 42
64
65 # Test that tree is unchanged
66 assert len(self.tree) == 10
67
68 def test_pop_with_key_present(self):
69 """Test pop() when key exists."""
70 # Pop existing key
71 value = self.tree.pop(5)
72 assert value == "value_5"
73
74 # Verify key is removed
75 assert 5 not in self.tree
76 assert len(self.tree) == 9
77
78 # Verify other keys still exist
79 assert self.tree[4] == "value_4"
80 assert self.tree[6] == "value_6"
81
82 def test_pop_with_key_missing_no_default(self):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected