@@ -18,7 +18,7 @@ def test_stack(self):
1818 self .assertEqual (myStack .peek (), 12 )
1919 self .assertFalse (myStack .isEmpty ())
2020
21- nullStack = stack .Stack ()
21+ nullStack = stack .Stack ()
2222
2323 self .assertEqual (nullStack .pop (), - 1 )
2424 self .assertEqual (nullStack .peek (), - 1 )
@@ -96,5 +96,30 @@ def test_binary_tree(self):
9696 expectedResult = [4 , 2 , 3 , 1 ]
9797 self .assertEqual (postorderTraversal , expectedResult )
9898
99+ class TestBinarySearchTree (unittest .TestCase ):
100+ def test_binary_search_tree (self ):
101+ root = tree .BinarySearchTree ()
102+ root .insert (10 )
103+ root .insert (12 )
104+ root .insert (5 )
105+ root .insert (4 )
106+ root .insert (20 )
107+ root .insert (8 )
108+ root .insert (7 )
109+ root .insert (15 )
110+ root .insert (13 )
111+
112+ inorder = root .inorder ()
113+ preorder = root .preorder ()
114+ postorder = root .postorder ()
115+ expectedResult = [4 , 5 , 7 , 8 , 10 , 12 , 13 , 15 , 20 ]
116+ self .assertEqual (inorder , expectedResult )
117+ expectedResult = [10 , 5 , 4 , 8 , 7 , 12 , 20 , 15 , 13 ]
118+ self .assertEqual (preorder , expectedResult )
119+ expectedResult = [4 , 7 , 8 , 5 , 13 , 15 , 20 , 12 , 10 ]
120+ self .assertEqual (postorder , expectedResult )
121+
122+ self .assertTrue (root .find (8 ))
123+
99124if __name__ == '__main__' :
100125 unittest .main ()
0 commit comments