BST Clear
by Isai Damier

  #=====================================================================
  # Author: Isai Damier
  # Title: clear
  # 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 clear( self ):
    self.root = None
import unittest
from algorithms.BST import BST
from cStringIO import StringIO
import sys
class Test( unittest.TestCase ):
  #=====================================================================
  # Test of clear method, of class BST.
  #=====================================================================
  def testClear( self ):
    bst = BST()

    self.assertEquals( True, bst.isEmpty() )
    self.assertEquals( 0, bst.size() )

    treeTape = [200, 100, 300, 50, 150, 250, 350, 25, 75, 125,
                      175, 225, 275, 325, 375, 35, 212, 312, 400]
    # load data into tree
    for i in treeTape:
      bst.add( i )

    self.assertEquals( False, bst.isEmpty() )
    self.assertEquals( len( treeTape ), bst.size() )
    for i in treeTape:
      self.assertIsNotNone( bst.find( i ) )

    bst.clear()

    self.assertEquals( True, bst.isEmpty() )
    self.assertEquals( 0, bst.size() )
    for i in treeTape:
      self.assertIsNone( bst.find( treeTape[0] ) )