def test_delete_transfer(self): self.manager.Node.n = 4 self.manager.insert(2, 32) self.manager.insert(24, 67) self.manager.insert(7, 87) self.manager.insert(15, 45) self.manager.insert(11, 43) self.manager.delete(24) self.assertEqual(self.manager.root, 3) Node = self.manager.Node root_block = BufferManager().get_file_block(self.manager.index_file_path, self.manager.root) root_node = Node.frombytes(root_block.read()) self.assertEqual(root_node.keys, [(11,)]) left_block = BufferManager().get_file_block(self.manager.index_file_path, 1) left_node = Node.frombytes(left_block.read()) self.assertEqual(left_node.keys, _convert_to_tuple_list([2, 7])) self.assertEqual(left_node.children, [32, 87, 2]) right_block = BufferManager().get_file_block(self.manager.index_file_path, 2) right_node = Node.frombytes(right_block.read()) self.assertEqual(right_node.keys, _convert_to_tuple_list([11, 15])) self.assertEqual(right_node.children, [43, 45, 0])
def test_fuse_internal(self): Node = node_factory('<i') parent = Node(False, [1, 14, 35], [54, 21, 518, 42]) left = Node(False, [2, 7, 11], [32, 87, 43, 518]) right = Node(False, [15, 24, 31], [45, 67, 89, 42]) left.fuse_with(right, parent, 1) self.assertEqual(parent.keys, _convert_to_tuple_list([1, 35])) self.assertEqual(parent.children, [54, 21, 42]) self.assertEqual(left.keys, _convert_to_tuple_list([2, 7, 11, 14, 15, 24, 31])) self.assertEqual(left.children, [32, 87, 43, 518, 45, 67, 89, 42])
def test_transfer_from_right_leaf(self): Node = node_factory('<i') parent = Node(False, [1, 14, 35], [54, 21, 518, 42]) left = Node(True, [2, 7, 11], [32, 87, 43, 518]) right = Node(True, [15, 24, 31], [45, 67, 89, 42]) left.transfer_from_right(right, parent, 1) self.assertEqual(parent.keys, _convert_to_tuple_list([1, 24, 35])) self.assertEqual(parent.children, [54, 21, 518, 42]) self.assertEqual(left.keys, _convert_to_tuple_list([2, 7, 11, 15])) self.assertEqual(left.children, [32, 87, 43, 45, 518]) self.assertEqual(right.keys, _convert_to_tuple_list([24, 31])) self.assertEqual(right.children, [67, 89, 42])
def test_delete_fuse(self): self.manager.Node.n = 4 self.manager.insert(2, 32) self.manager.insert(24, 67) self.manager.insert(7, 87) self.manager.insert(15, 45) self.manager.insert(11, 43) self.manager.delete(24) self.manager.delete(11) self.assertEqual(self.manager.root, 1) Node = self.manager.Node root_block = BufferManager().get_file_block(self.manager.index_file_path, self.manager.root) root_node = Node.frombytes(root_block.read()) self.assertEqual(root_node.is_leaf, True) self.assertEqual(root_node.keys, _convert_to_tuple_list([2, 7, 15])) self.assertEqual(root_node.children, [32, 87, 45, 0])
def test_convert_to_tuples(self): self.assertEqual(_convert_to_tuple_list([42, 666]), [(42,), (666,)]) self.assertEqual(_convert_to_tuple_list([[42, 666, 'spam'], (233, 987, 'foo')]), [(42, 666, 'spam'), (233, 987, 'foo')])