import javabook.*;

/*
 * Introduction to OOP with Java 2nd Edition, McGraw-Hill
 *	
 *  A sample program to test the binary search.
 *  
 * @author Dr. Caffeine
 *
 */
class TestBinarySearch
{
    
    private final static int EMPTY = -1;
    
    public static void main (String[] args)
    {
        MainWindow  mainWindow;
        OutputBox 	outputBox;
        
        mainWindow = new MainWindow("Test Binary Search");
        outputBox  = new OutputBox( mainWindow );
                
        mainWindow.setVisible( true );
        outputBox.setVisible( true );
        
        int[ ] number   = new int[1000];
        
        Search mySearch = new Search( );
        
        int    position;
       
        //Store elements into the array
        //Note: the binary search requires a sorted list
        for (int i = 0; i < number.length; i++ ) {
            
            number[i] = i * 4;    //any number is fine
                                  //as long as the array elements
                                  //are in ascending order
            
        }
        
        
        //Test binary search
        
        position = mySearch.binarySearch( number, 100 );
        
        outputBox.printLine( "Search 100; Index returned:   " + position );
        
        position = mySearch.binarySearch( number, 40 );
        
        outputBox.printLine( "Search 40; Index returned:   " + position );
        
        position = mySearch.binarySearch( number, 98765 );
        
        outputBox.printLine( "Search 98765; Index returned: " + position );
            
    }
    
}