From 0edb1525ea95d54ea0ac2c0cc0d9afb498f74402 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Sat, 2 Jun 2018 08:51:45 +0300 Subject: [PATCH] Throw error on remove from red-black tree. --- .../tree/red-black-tree/RedBlackTree.js | 8 ++++++++ .../tree/red-black-tree/__test__/RedBlackTree.test.js | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/data-structures/tree/red-black-tree/RedBlackTree.js b/src/data-structures/tree/red-black-tree/RedBlackTree.js index d00a6730..2bd3afd4 100644 --- a/src/data-structures/tree/red-black-tree/RedBlackTree.js +++ b/src/data-structures/tree/red-black-tree/RedBlackTree.js @@ -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 */ diff --git a/src/data-structures/tree/red-black-tree/__test__/RedBlackTree.test.js b/src/data-structures/tree/red-black-tree/__test__/RedBlackTree.test.js index c26763e3..cf5a54c4 100644 --- a/src/data-structures/tree/red-black-tree/__test__/RedBlackTree.test.js +++ b/src/data-structures/tree/red-black-tree/__test__/RedBlackTree.test.js @@ -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(); + }); });