title: How would I create a function to test my Tree before an algorithm runs?
body: <p>For the following code below, I am looking for some sort of way to add testing data. How would I go about creating a function to check that the Huffman Tree is checked and confirmed as working before the algorithm executes?
  Thanks in advance for any help!</p>
  <pre><code>#Huffman Coding Algorithm
  
  string = input(&quot;Please Enter a Phrase Consister of Letters and or Spaces: &quot; + &quot;\n&quot;)
  print(&quot;&quot;)
  
  
  #Creating the tree nodes
  class HuffmanTree(object):
      
      def __init__(self, left = None, right = None):
          self.left = left
          self.right = right
      
      def child(self):
          return(self.left, self.right)
      
      def nodes(self):
          return (self.left, self.right)
  
      def __str__(self):
          return &quot;%s_%s&quot; % (self.left, self.right)
  
  #Main function for Huffman coding. 
  def Huffman_Compression(node, left = True, binString = &quot;&quot;):
      if type(node) is str:
          return {node: binString}
      (left, right) = node.child()
      dt = dict()
      dt.update(Huffman_Compression(left, True, binString + &quot;0&quot;))
      dt.update(Huffman_Compression(right, False, binString + &quot;1&quot;))
      return dt
  
  #Calculating the frequency of characters 
  freq = {}
  for c in string:
      if c in freq:
          freq[c] += 1
      else:
          freq[c] = 1
          
  freq = sorted(freq.items(), key = lambda x: x[1], reverse = True)
  
  nodes = freq
  
  while len(nodes) &gt; 1:
      (key1, c1) = nodes[-1]
      (key2, c2) = nodes[-2]
      nodes = nodes[:-2]
      node = HuffmanTree(key1, key2)
      nodes.append((node, c1 + c2))
      
      nodes = sorted(nodes, key = lambda x: x[1], reverse = True)
      
  huffmancoding = Huffman_Compression(nodes[0][0])
  
  print(&quot; Characters | Huffman Output &quot;)
  print(&quot;-------------------------------&quot;)
  
  for (char, frequency) in freq:
      print(&quot; %-4r |%12s&quot; % (char, huffmancoding[char]))
  </code></pre>