Skip to content

Commit

Permalink
Throw error on remove from red-black tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
trekhleb committed Jun 2, 2018
1 parent 26d6b78 commit 0edb152
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/data-structures/tree/red-black-tree/RedBlackTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ export default class RedBlackTree extends BinarySearchTree {
return insertedNode;
}

/**
* @param {*} value
* @return {BinarySearchTreeNode}
*/
remove(value) {
throw new Error(`Can't remove ${value}. Remove method is not implemented yet`);
}

/**
* @param {BinarySearchTreeNode} node
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,14 @@ describe('RedBlackTree', () => {
expect(tree.toString()).toBe('15,17,19,20,25');
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();
});
});

0 comments on commit 0edb152

Please sign in to comment.