Test LeafNode operations
| 184 | |
| 185 | |
| 186 | class TestLeafNode: |
| 187 | """Test LeafNode operations""" |
| 188 | |
| 189 | def test_leaf_node_creation(self): |
| 190 | """Test creating a leaf node""" |
| 191 | leaf = LeafNode(capacity=4) |
| 192 | assert leaf.is_leaf() |
| 193 | assert not leaf.is_full() |
| 194 | assert len(leaf) == 0 |
| 195 | |
| 196 | def test_leaf_node_insert(self): |
| 197 | """Test inserting into a leaf node""" |
| 198 | leaf = LeafNode(capacity=4) |
| 199 | |
| 200 | # Insert first item |
| 201 | assert leaf.insert(2, "two") is None |
| 202 | assert len(leaf) == 1 |
| 203 | assert leaf.get(2) == "two" |
| 204 | |
| 205 | # Insert before |
| 206 | assert leaf.insert(1, "one") is None |
| 207 | assert len(leaf) == 2 |
| 208 | assert leaf.keys == [1, 2] |
| 209 | |
| 210 | # Insert after |
| 211 | assert leaf.insert(3, "three") is None |
| 212 | assert len(leaf) == 3 |
| 213 | assert leaf.keys == [1, 2, 3] |
| 214 | |
| 215 | # Update existing |
| 216 | assert leaf.insert(2, "TWO") == "two" |
| 217 | assert len(leaf) == 3 |
| 218 | assert leaf.get(2) == "TWO" |
| 219 | |
| 220 | def test_leaf_node_full(self): |
| 221 | """Test when leaf node is full""" |
| 222 | leaf = LeafNode(capacity=4) |
| 223 | |
| 224 | # Fill the node |
| 225 | for i in range(4): |
| 226 | leaf.insert(i, str(i)) |
| 227 | |
| 228 | assert leaf.is_full() |
| 229 | assert len(leaf) == 4 |
| 230 | |
| 231 | def test_leaf_find_position(self): |
| 232 | """Test finding position for keys""" |
| 233 | leaf = LeafNode(capacity=4) |
| 234 | leaf.insert(10, "ten") |
| 235 | leaf.insert(20, "twenty") |
| 236 | leaf.insert(30, "thirty") |
| 237 | |
| 238 | # Test finding existing keys |
| 239 | assert leaf.find_position(10) == (0, True) |
| 240 | assert leaf.find_position(20) == (1, True) |
| 241 | assert leaf.find_position(30) == (2, True) |
| 242 | |
| 243 | # Test finding non-existing keys |
nothing calls this directly
no outgoing calls
no test coverage detected