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_initial_insert(self): manager = IndexManager('spam', '<id') manager.insert([42, 7.6], 518) self.assertEqual(manager.root, 1) self.assertEqual(manager.first_deleted_block, 0) self.assertEqual(manager.total_blocks, 2) block = BufferManager().get_file_block('spam', 1) Node = manager.Node node = Node.frombytes(block.read()) self.assertEqual(node.is_leaf, True) self.assertEqual(node.keys, [(42, 7.6)]) self.assertEqual(node.children, [518, 0])
def test_multiple_delete(self): manager = IndexManager('spam', '<id') manager.insert([42, 7.6], 518) manager.insert([42, 7.6], 212) manager.insert([233, 66.6], 7) deleted_num = manager.delete([42, 7.6]) self.assertEqual(deleted_num, 2) self.assertEqual(manager.root, 1) self.assertEqual(manager.first_deleted_block, 0) self.assertEqual(manager.total_blocks, 2) block = BufferManager().get_file_block('spam', 1) Node = manager.Node node = Node.frombytes(block.read()) self.assertEqual(node.is_leaf, True) self.assertEqual(node.keys, [(233, 66.6)]) self.assertEqual(node.children, [7, 0])
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_persistence(self): manager = IndexManager('spam', '<id') manager.insert([42, 7.6], 518) manager.insert([233, 66.6], 7) manager.delete([42, 7.6]) manager.dump_header() manager._manager.flush_all() del manager manager = IndexManager('spam', '<id') self.assertEqual(manager.root, 1) self.assertEqual(manager.first_deleted_block, 0) self.assertEqual(manager.total_blocks, 2) block = BufferManager().get_file_block('spam', 1) Node = manager.Node node = Node.frombytes(block.read()) self.assertEqual(node.is_leaf, True) self.assertEqual(node.keys, [(233, 66.6)]) self.assertEqual(node.children, [7, 0])