Test copy() method creates a shallow copy.
(self)
| 236 | assert self.tree[5] == "updated_five" |
| 237 | |
| 238 | def test_copy(self): |
| 239 | """Test copy() method creates a shallow copy.""" |
| 240 | # Create a copy |
| 241 | copied_tree = self.tree.copy() |
| 242 | |
| 243 | # Should be a different object |
| 244 | assert copied_tree is not self.tree |
| 245 | |
| 246 | # But should have same capacity and contents |
| 247 | assert copied_tree.capacity == self.tree.capacity |
| 248 | assert len(copied_tree) == len(self.tree) |
| 249 | |
| 250 | # Check all key-value pairs |
| 251 | for key in range(10): |
| 252 | assert copied_tree[key] == self.tree[key] |
| 253 | |
| 254 | # Modifications to copy shouldn't affect original |
| 255 | copied_tree[100] = "new_value" |
| 256 | assert 100 not in self.tree |
| 257 | assert len(self.tree) == 10 |
| 258 | |
| 259 | # Modifications to original shouldn't affect copy |
| 260 | self.tree[200] = "another_value" |
| 261 | assert 200 not in copied_tree |
| 262 | |
| 263 | def test_copy_empty_tree(self): |
| 264 | """Test copy() of empty tree.""" |