From e3822b9cacd4e5c403c13616822e32b2d0ecfa2f Mon Sep 17 00:00:00 2001 From: Krzysztof <60067306+gikf@users.noreply.github.com> Date: Tue, 26 Oct 2021 06:07:12 +0200 Subject: [PATCH] fix(curriculum): test removing non-existing element from empty and non-empty tree (#43885) * fix: test removing element not in a tree * fix: test removing from empty tree --- ...ete-a-leaf-node-in-a-binary-search-tree.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/curriculum/challenges/english/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md b/curriculum/challenges/english/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md index 43d58845d2..a359575e5f 100644 --- a/curriculum/challenges/english/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md +++ b/curriculum/challenges/english/10-coding-interview-prep/data-structures/delete-a-leaf-node-in-a-binary-search-tree.md @@ -46,6 +46,25 @@ assert( ); ``` +Trying to remove an element from an empty tree should return `null`. + +```js +assert( + (function () { + var test = false; + if (typeof BinarySearchTree !== 'undefined') { + test = new BinarySearchTree(); + } else { + return false; + } + if (typeof test.remove !== 'function') { + return false; + } + return test.remove(100) == null; + })() +); +``` + Trying to remove an element that does not exist should return `null`. ```js @@ -60,6 +79,8 @@ assert( if (typeof test.remove !== 'function') { return false; } + test.add(15); + test.add(30); return test.remove(100) == null; })() );