Throw error on remove from red-black tree.

This commit is contained in:
Oleksii Trekhleb 2018-06-02 08:51:45 +03:00
parent 26d6b7877d
commit 0edb1525ea
2 changed files with 18 additions and 0 deletions

View File

@ -32,6 +32,14 @@ export default class RedBlackTree extends BinarySearchTree {
return insertedNode; return insertedNode;
} }
/**
* @param {*} value
* @return {BinarySearchTreeNode}
*/
remove(value) {
throw new Error(`Can't remove ${value}. Remove method is not implemented yet`);
}
/** /**
* @param {BinarySearchTreeNode} node * @param {BinarySearchTreeNode} node
*/ */

View File

@ -311,4 +311,14 @@ describe('RedBlackTree', () => {
expect(tree.toString()).toBe('15,17,19,20,25'); expect(tree.toString()).toBe('15,17,19,20,25');
expect(tree.root.height).toBe(2); expect(tree.root.height).toBe(2);
}); });
it('should throw an error when trying to remove node', () => {
const removeNodeFromRedBlackTree = () => {
const tree = new RedBlackTree();
tree.remove(1);
};
expect(removeNodeFromRedBlackTree).toThrowError();
});
}); });