IsBST { public boolean checkIterative(BinaryNode<Integer> root) { validateInput(root); List<BinaryNode<Integer>> nodesInOrder = binaryTreeInOrder.getRecursive(root); return isListOrdered(nodesInOrder); }  boolean checkRecursive(BinaryNode<Integer> root); boolean checkIterative(BinaryNode<Integer> root);  }
@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullBinaryTreesIterative() { isBST.checkIterative(null); }
@Test public void shouldReturnTrueIfTheTreeContainsJustOneNodeIterative() { BinaryNode<Integer> root = new BinaryNode<Integer>(0); assertTrue(isBST.checkIterative(root)); }
@Test public void shouldReturnFalseIfLeftNodesAreGraterThanRightNodesIterative() { BinaryNode<Integer> root = new BinaryNode<Integer>(0); BinaryNode<Integer> n1 = new BinaryNode<Integer>(1); BinaryNode<Integer> n2 = new BinaryNode<Integer>(2); root.setLeft(n2); root.setRight(n1); assertFalse(isBST.checkIterative(root)); }
@Test public void shouldReturnTrueIfBinaryTreeIsBSTIterative() { BinaryNode<Integer> root = new BinaryNode<Integer>(0); BinaryNode<Integer> n1 = new BinaryNode<Integer>(1); BinaryNode<Integer> n2 = new BinaryNode<Integer>(2); n1.setLeft(root); n1.setRight(n2); assertTrue(isBST.checkIterative(n1)); }