BST Is Empty
by Isai Damier, Android Engineer @ Google
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | #===================================================================== # Author: Isai Damier # Title: Is Empty # Project: geekviewpoint # Package: algorithms # # Time Complexity of Solution: # Best = Average = Worst = const. # #===================================================================== class BST( object ): def __init__( self ): self .root = None def getRoot( self ): return self .root def isEmpty( self ): return self .root is None |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | import unittest from algorithms.BST import BST from cStringIO import StringIO import sys class Test( unittest.TestCase ): #===================================================================== # Test of isEmpty method, of class BST. #===================================================================== def testIsEmpty( self ): bst = BST() expResult = True result = bst.isEmpty() self .assertEquals( expResult, result ) bst.add( 5 ) result = bst.isEmpty() expResult = False self .assertEquals( expResult, result ) |