/**
* Unit test cases for the implementation of a Binary Search Tree.
*/
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class BSTreeTest
{
/**
* the tree to use for testing
*/
private BSTree<Integer> tree;
// returns a tree loaded with the given items
private static BSTree<Integer> load( Integer... items )
{
IntComparator compare = new IntComparator();
BSTree<Integer> tree = new BSTree<Integer>(compare);
for (Integer value : items) {
tree.addLoop(value);
}
return tree;
}
@Test
public void test_addLoop()
{
// testing empty
tree = load( );
tree.addLoop( a );
assertEquals( tree.toString(), "[?]" );
// testing single
tree = load( a );
tree.addLoop( b );
assertEquals( tree.toString(), "[? ?]" );
*** one test case for single is not enough ***
// testing multi
tree = load( a, b, c, d, e, f, g );
tree.addLoop( h );
assertEquals( tree.toString(), "[? ? ? ... ?]" );
*** one test case for multi is not enough ***
}
@Test
public void test_maxValueLoop()
{
// testing empty
tree = load( );
assertThrowsExactly( WhichException.class, () -> tree.maxValueLoop() );
assertEquals( tree.toString(), "[?]" );
// testing single
tree = load( a );
assertTrue( tree.maxValueLoop() == ? );
assertEquals( tree.toString(), "[?]" );
// testing multi
tree = load( a, b, c, d, e, f, g );
assertTrue( tree.maxValueLoop() == ? );
assertEquals( tree.toString(), "[? ? ? ... ?]" );
}
}