title: isSemiBalanced() Java BST method not passing test
body: <p>I'm using Intellij IDEA and am testing my BST to see if it is semi-balanced. Semi-balanced (at least as this project specifies) means that every node in the tree is semi-balanced:</p>
  
  <p>A node with 0 children is semi-perfect.</p>
  
  <p>A node with 1 child is NOT semi-perfect.</p>
  
  <p>A node with 2 children is semi-perfect if (size-of-larger-child &lt;= size-of-smaller-child * 3)</p>
  
  <p>I've implemented the following code in eclipse. It passes every BST I've thrown at it but it will not pass this test in Intellij IDEA. I've included my method below (that works in Eclipse when ran through the main() function) and also the test that my method must pass in IDEA (which it does not, and is currently my problem). The test is written in Scala. Thanks guys.  </p>
  
  <pre><code>  //My Java method and helper method
    public static boolean isSemiBalanced (Node t) {
      int n = isSemiBalancedInt(t);
      if (n &lt;= -1) return false;
      return true;
    }
  
    private static int isSemiBalancedInt(Node node) {
      if (node == null) return 1;
      if (node.left == null &amp;&amp; node.right == null) return 0;
      else if (node.left == null || node.right == null) return -1;
      else {
        int sizeMax = Math.max(isSemiBalancedInt(node.left), isSemiBalancedInt(node.right));
        int sizeMin = Math.min(isSemiBalancedInt(node.left), isSemiBalancedInt(node.right));
        if (sizeMax == -1 || sizeMin == -1) return -1;
        if (sizeMax &lt;= 3 * sizeMin) return isSemiBalancedInt(node.left) + isSemiBalancedInt(node.right);
      }
      return -1;
    }
  
  
  //Scala code that checks my Java method
  import org.scalatest._
  import org.scalacheck.Gen
  
  class hw1tests extends UnitSpec {
    val EX : Map[Int, Tag] = 
      (for (i &lt;- (1 to 12).toList) yield {
        object T extends Tag ("hw1ex%02d".format (i))
        (i, T)
      }).toMap
  
    import hw1._
    import hw1.NodeSamples._
    import stdlib._
  
    val trees : List[Node] = List (t01, t02, t03, t04, t05, t06, t07, t08, t09, t10)
    val treesCopy : List[Node] = for (t &lt;- trees) yield NodeOps.copy (t)
  
    def compareToDepth (t1 : Node, t2 : Node, k : Int) : Boolean = {
      if (k &lt; 0) {
        true
      } else if ((t1 eq null) || (t2 eq null)) {
        t1 eq t2
      } else {
        (t1.key == t2.key) &amp;&amp; compareToDepth (t1.left, t2.left, k - 1) &amp;&amp; compareToDepth (t1.right, t2.right, k - 1)
      }
    }
  
    def traversal (t : Node) : List[Int] = {
      if (t eq null) {
        Nil
      } else {
        traversal (t.left) ++ List (t.key) ++ traversal (t.right)
      }
    }
  
    def noChange () = {
      for ((t1, t2) &lt;- trees.zip (treesCopy)) {
        assert (compareToDepth (t1, t2, 10) === true)
      }
    }
  
    property ("EX09 - isSemiBalancedTest", EX (9)) {
      val sizeTable = Table (
        ("t", "isSemiBalanced (t)"),
        (t01,  true),
        (t02, false),
        (t03, false),
        (t04,  true),
        (t05,  true),
        (t06, false),
        (t07,  true),
        (t08,  true),
        (t09,  true),
        (t10,  true)
      )
      forAll (sizeTable) { (t : Node, res : Boolean) =&gt;
        assert (NodeOps.isSemiBalanced (t) ===  res)
      }
      noChange
    }
  </code></pre>