@@ -46,7 +46,7 @@ describe('RedBlackTree', () => {
4646 expect ( tree . root . left . color ) . toBe ( RED ) ;
4747 } ) ;
4848
49- xit ( 'should balance tree by rotating right' , ( ) => {
49+ it ( 'should balance tree by rotating right' , ( ) => {
5050 tree . add ( 3 ) ;
5151 tree . add ( 2 ) ;
5252 tree . add ( 1 ) ;
@@ -56,12 +56,56 @@ describe('RedBlackTree', () => {
5656 1 , 3 ,
5757 undefined , undefined , undefined , undefined ,
5858 ] ) ;
59+
60+ // verify colors
61+ expect ( tree . root . color ) . toBe ( BLACK ) ;
62+ expect ( tree . root . right . color ) . toBe ( RED ) ;
63+ expect ( tree . root . left . color ) . toBe ( RED ) ;
5964 } ) ;
6065
6166 it ( 'should change colors' , ( ) => {
62- tree . add ( 1 ) ;
63- tree . add ( 2 ) ;
64- tree . add ( 3 ) ;
67+ const n1 = tree . add ( 1 ) ;
68+ const n2 = tree . add ( 2 ) ;
69+ const n3 = tree . add ( 3 ) ;
70+ const n4 = tree . add ( 4 ) ;
71+
72+ expect ( tree . toArray ( ) ) . toEqual ( [
73+ 2 ,
74+ 1 , 3 ,
75+ undefined , undefined , undefined , 4 ,
76+ undefined , undefined ,
77+ ] ) ;
78+
79+ expect ( tree . root . color ) . toBe ( BLACK ) ;
80+ expect ( tree . root . right . color ) . toBe ( BLACK ) ;
81+ expect ( tree . root . left . color ) . toBe ( BLACK ) ;
82+ expect ( tree . root . right . right . color ) . toBe ( RED ) ;
83+
84+ expect ( n1 . color ) . toBe ( BLACK ) ;
85+ expect ( n2 . color ) . toBe ( BLACK ) ;
86+ expect ( n3 . color ) . toBe ( BLACK ) ;
87+ expect ( n4 . color ) . toBe ( RED ) ;
88+ } ) ;
89+
90+ xtest ( 'letf roation with grandparent' , ( ) => {
91+ const n1 = tree . add ( 1 ) ;
92+ const n2 = tree . add ( 2 ) ;
93+ const n3 = tree . add ( 3 ) ;
94+ const n4 = tree . add ( 4 ) ;
95+ const n5 = tree . add ( 5 ) ;
96+
97+ expect ( tree . toArray ( ) ) . toEqual ( [
98+ 2 ,
99+ 1 , 4 ,
100+ undefined , undefined , 3 , 5 ,
101+ undefined , undefined , undefined , undefined ,
102+ ] ) ;
103+
104+ expect ( n1 . color ) . toBe ( BLACK ) ;
105+ expect ( n2 . color ) . toBe ( BLACK ) ;
106+ expect ( n4 . color ) . toBe ( BLACK ) ;
107+ expect ( n3 . color ) . toBe ( RED ) ;
108+ expect ( n5 . color ) . toBe ( RED ) ;
65109 } ) ;
66110 } ) ;
67111} ) ;
0 commit comments