package com.github.foo;

import org.junit.Assert;
import org.junit.Test;

/**
 * Test cases for BinarySearchTree
 * @author Sachin
 *
 */
public class BinarySearchTreeTest {
	
	
	private BinarySearchTree<Integer> getBinaryTree(){
		
		BinarySearchTree<Integer> btree = new BinarySearchTree<>(50);
		btree.insert(10);
		btree.insert(60);
		btree.insert(20);
		btree.insert(70);
		btree.insert(65);
		btree.insert(15);
		return btree;
	}
	
	@Test
	public void rootNodeWithNoChildHasOneHeight() {
		Tree<Integer> btree = new BinarySearchTree<Integer>(10);
		Assert.assertEquals("Height is not null", 1, btree.height());
	}
	
	@Test
	public void rootNodeWithTwoChildHasThreeHeight() {
		Tree<Integer> btree = new BinarySearchTree<Integer>(10);
		btree.insert(20);
		btree.insert(30);
		Assert.assertEquals("Height is not null", 3, btree.height());
	}
	
	@Test
	public void bstInorderTraverse() {
		
		Assert.assertArrayEquals(new Integer[] {10, 15, 20, 50, 60, 65, 70}, Trees.traverseBinaryTree(getBinaryTree().getRoot(), Order.IN));
	}
	
	@Test
	public void bstLevelOrderTraverse() {
		
		Assert.assertArrayEquals(new Integer[] {50,10,60,20,70,15,65}, Trees.traverseBinaryTree(getBinaryTree().getRoot(), Order.LEVEL));
	}
}

@@ -1262,11 +1262,253 @@
 );%0D%0A%09%7D%0D%0A
+%09%0D%0A%09@Test%0D%0A%09public void bstRemoveNode() %7B%0D%0A%09%09BinarySearchTree%3CInteger%3E bTree= getBinaryTree();%0D%0A%09%09bTree.remove(50);%0D%0A%09%09Assert.assertArrayEquals(new Integer%5B%5D %7B10, 15, 20,60, 65, 70%7D, Trees.traverseBinaryTree(bTree.getRoot(), Order.IN));%0D%0A%09%7D%0D%0A
 %7D%0D%0A

Test case for remove node