From 48f7ea1ad509b333bf5a0135fc35ac97a25f1d59 Mon Sep 17 00:00:00 2001 From: Oleksii Trekhleb Date: Fri, 1 Jun 2018 10:52:23 +0300 Subject: [PATCH] Add one more test for BST. --- .../__test__/BinarySearchTree.test.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTree.test.js b/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTree.test.js index 9262474c..593014d8 100644 --- a/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTree.test.js +++ b/src/data-structures/tree/binary-search-tree/__test__/BinarySearchTree.test.js @@ -76,4 +76,23 @@ describe('BinarySearchTree', () => { expect(bst.toString()).toBe('obj1,obj2,obj3'); }); + + it('should be traversed to sorted array', () => { + const bst = new BinarySearchTree(); + + bst.insert(10); + bst.insert(-10); + bst.insert(20); + bst.insert(-20); + bst.insert(25); + bst.insert(6); + + expect(bst.toString()).toBe('-20,-10,6,10,20,25'); + expect(bst.root.height).toBe(2); + + bst.insert(4); + + expect(bst.toString()).toBe('-20,-10,4,6,10,20,25'); + expect(bst.root.height).toBe(3); + }); });