1- import { BinaryTree } from "../ts/BinaryTree" ;
1+ import { BinaryTree } from "../ts/BinaryTree/BinaryTree " ;
22
33describe ( 'BinaryTree' , function ( ) {
44 describe ( 'add' , function ( ) {
55 it ( 'should be able to add node' , function ( ) {
6- var tree = new BinaryTree < number > ( ) ;
6+ const tree = new BinaryTree < number > ( ) ;
77 tree . add ( 2 ) ;
88 expect ( tree . root . value ) . toEqual ( 2 ) ;
99 tree . add ( 1 ) ;
1010 expect ( tree . root . left . value ) . toEqual ( 1 ) ;
1111 } ) ;
1212 it ( 'should be able to add node' , function ( ) {
13- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
13+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
1414 tree . add ( 5 ) ;
1515 expect ( tree . root . value ) . toEqual ( 5 ) ;
1616 tree . add ( 6 ) ;
@@ -21,7 +21,7 @@ describe('BinaryTree', function () {
2121 } ) ;
2222
2323 it ( 'should be able to add node to binary tree with object values' , function ( ) {
24- var tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
24+ const tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
2525 tree . add ( { amount : 5 } ) ;
2626 expect ( tree . root . value ) . toEqual ( { amount : 5 } ) ;
2727 tree . add ( { amount : 6 } ) ;
@@ -31,7 +31,7 @@ describe('BinaryTree', function () {
3131 } ) ;
3232
3333 it ( 'should be able to walk the binary tree in order' , function ( ) {
34- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
34+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
3535 tree . add ( 5 ) ;
3636 tree . add ( 6 ) ;
3737 tree . add ( 4 ) ;
@@ -44,7 +44,7 @@ describe('BinaryTree', function () {
4444 } ) ;
4545
4646 it ( 'should be able to walk the binary tree that has object values in order' , function ( ) {
47- var tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
47+ const tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
4848 tree . add ( { amount : 6 } ) ;
4949 tree . add ( { amount : 4 } ) ;
5050 tree . add ( { amount : 5 } ) ;
@@ -58,7 +58,7 @@ describe('BinaryTree', function () {
5858
5959
6060 it ( 'should be able to walk the binary tree in order' , function ( ) {
61- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
61+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
6262 tree . add ( 5 ) ;
6363 tree . add ( 6 ) ;
6464 tree . add ( 4 ) ;
@@ -71,7 +71,7 @@ describe('BinaryTree', function () {
7171 } ) ;
7272
7373 it ( 'should be able to walk the binary tree in reverseorder' , function ( ) {
74- var tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
74+ const tree = new BinaryTree < any > ( function ( a , b ) { return a . amount > b . amount ; } ) ;
7575 tree . add ( { amount : 6 } ) ;
7676 tree . add ( { amount : 4 } ) ;
7777 tree . add ( { amount : 5 } ) ;
@@ -85,20 +85,20 @@ describe('BinaryTree', function () {
8585
8686 describe ( ' search' , function ( ) {
8787 it ( 'should return null when no root' , function ( ) {
88- var tree = new BinaryTree < any > ( function ( a , b ) { return a > b ; } ) ;
88+ const tree = new BinaryTree < any > ( function ( a , b ) { return a > b ; } ) ;
8989 expect ( tree . search ( 5 ) ) . toBeNull ( ) ;
9090 } ) ;
9191
9292 it ( 'should return element when found' , function ( ) {
93- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
93+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
9494 tree . add ( 5 ) ;
9595 expect ( tree . search ( 5 ) . value ) . toEqual ( 5 ) ;
9696 tree . add ( 6 ) ;
9797 expect ( tree . search ( 6 ) . value ) . toEqual ( 6 ) ;
9898 } ) ;
9999
100100 it ( 'should return null when no element was found' , function ( ) {
101- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
101+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
102102 tree . add ( 5 ) ;
103103 expect ( tree . search ( 23 ) ) . toBeNull ( ) ;
104104 tree . add ( 6 ) ;
@@ -107,7 +107,7 @@ describe('BinaryTree', function () {
107107 } ) ;
108108
109109 it ( 'should be able to get max value' , function ( ) {
110- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
110+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
111111 expect ( tree . min ( ) ) . toBeNull ( ) ;
112112 tree . add ( 1 ) ;
113113 tree . add ( 2 ) ;
@@ -117,7 +117,7 @@ describe('BinaryTree', function () {
117117 } ) ;
118118
119119 it ( 'should be able to get min value' , function ( ) {
120- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
120+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
121121 expect ( tree . max ( ) ) . toBeNull ( ) ;
122122 tree . add ( 1 ) ;
123123 tree . add ( 2 ) ;
@@ -127,56 +127,56 @@ describe('BinaryTree', function () {
127127 } ) ;
128128
129129 it ( 'should be able to get node successor' , function ( ) {
130- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
130+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
131131 tree . add ( 1 ) ;
132132 tree . add ( 2 ) ;
133133 tree . add ( 4 ) ;
134134 tree . add ( 5 ) ;
135- expect ( tree . sucessor ( 2 ) . value ) . toEqual ( 4 ) ;
135+ expect ( tree . successor ( 2 ) . value ) . toEqual ( 4 ) ;
136136 } ) ;
137137
138138 it ( 'should be able to get node successor when it doesn\'t have right child' , function ( ) {
139- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
139+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
140140 tree . add ( 1 ) ;
141141 tree . add ( 10 ) ;
142142 tree . add ( 9 ) ;
143143 tree . add ( 8 ) ;
144- expect ( tree . sucessor ( 8 ) . value ) . toEqual ( 9 ) ;
145- expect ( tree . sucessor ( 9 ) . value ) . toEqual ( 10 ) ;
144+ expect ( tree . successor ( 8 ) . value ) . toEqual ( 9 ) ;
145+ expect ( tree . successor ( 9 ) . value ) . toEqual ( 10 ) ;
146146 } ) ;
147147
148148 it ( 'should return null for node successor if tree is empty' , function ( ) {
149- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
150- expect ( tree . sucessor ( 2 ) ) . toBeNull ( ) ;
149+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
150+ expect ( tree . successor ( 2 ) ) . toBeNull ( ) ;
151151 } ) ;
152152
153153 it ( 'should return null if there is no successor' , function ( ) {
154- var tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
154+ const tree = new BinaryTree < number > ( function ( a , b ) { return a > b ; } ) ;
155155 tree . add ( 1 ) ;
156- expect ( tree . sucessor ( 1 ) ) . toBeNull ( ) ;
156+ expect ( tree . successor ( 1 ) ) . toBeNull ( ) ;
157157 tree . add ( 2 ) ;
158158 tree . add ( 4 ) ;
159159 tree . add ( 5 ) ;
160- expect ( tree . sucessor ( 5 ) ) . toBeNull ( ) ;
161- expect ( tree . sucessor ( 4 ) . value ) . toEqual ( 5 ) ;
160+ expect ( tree . successor ( 5 ) ) . toBeNull ( ) ;
161+ expect ( tree . successor ( 4 ) . value ) . toEqual ( 5 ) ;
162162 } ) ;
163163
164164 describe ( 'delete' , function ( ) {
165165 it ( `should return false if node was not found` , function ( ) {
166- var tree = new BinaryTree < number > ( ) ;
166+ const tree = new BinaryTree < number > ( ) ;
167167 expect ( tree . delete ( 1 ) ) . toEqual ( false ) ;
168168 } ) ;
169169
170170 it ( `should remove node if it doesn't have children` , function ( ) {
171- var tree = new BinaryTree < number > ( ) ;
171+ const tree = new BinaryTree < number > ( ) ;
172172 tree . add ( 1 ) ;
173173 expect ( tree . search ( 1 ) ) . not . toBeNull ( ) ;
174174 tree . delete ( 1 ) ;
175175 expect ( tree . search ( 1 ) ) . toBeNull ( ) ;
176176 } ) ;
177177
178178 it ( `should move the left child up if the node to remove has only left child and no right child` , function ( ) {
179- var tree = new BinaryTree < number > ( ) ;
179+ const tree = new BinaryTree < number > ( ) ;
180180 tree . add ( 2 ) ;
181181 tree . add ( 1 ) ;
182182 expect ( tree . search ( 2 ) ) . not . toBeNull ( ) ;
@@ -186,7 +186,7 @@ describe('BinaryTree', function () {
186186 } ) ;
187187
188188 it ( `should move the right child up if the node to remove has only right child and no left child` , function ( ) {
189- var tree = new BinaryTree < number > ( ) ;
189+ const tree = new BinaryTree < number > ( ) ;
190190 tree . add ( 1 ) ;
191191 tree . add ( 2 ) ;
192192 expect ( tree . search ( 1 ) ) . not . toBeNull ( ) ;
0 commit comments