/*
 * TesterOfTSAIHas.java
 *
 * Created on 28. April 2005, 18:14
 */

/**
 *
 * @author hug
 */
public class TesterOfTSAIHas
{
    private static final int min = -1000;
    private static final int max = 1000;
	
    private static java.util.Random random = new java.util.Random();
    
    private static int randomItem () 
    {
        int result = random.nextInt(max - min + 1) - min;
        assert min <= result : "postcondition";
	assert result <= max : "postcondition";
	return result;
    }
	
    private static void initRandom (int[] array)
    {
	assert array != null : "precondition";
        for (int index = 0; index < array.length; ++index)
	{
            array[index] = randomItem();
	}
    }

    private static void print (int[] array)
    {
	assert array != null : "precondition";
        System.out.print("[");
	for (int index = 0; index < array.length; ++index)
	{
            System.out.print(array[index] + " ");
	}
	System.out.println("]");
    }
	
    public static void main (String[] args)
    {
	if (args.length < 1)
        {
            System.out.println
                ("Please call this command with a positive integer argument!");
            return;
	} 
        int size = 0;
        try 
        {
            size = Integer.parseInt(args[0]);
        }
        catch (Exception e)
        {
            System.out.println
                ("Please call this command with a positive integer argument!");
            return;
        }
        if (size <= 0)
        {
            System.out.println
                ("Please call this command with a positive integer argument!");
            return;
        }
        int[] array = new int[size];
        initRandom(array); 
        ToolsetArrayInteger.gapsort(array);
        int item = randomItem();
        System.out.print("array: ");
        print(array);
        System.out.print("item " + item);
        if (!ToolsetArrayInteger.has(array, item)) 
        {
            System.out.print(" not");
        }
        System.out.print(" found in array.");
    }
}
