/**
 *  Benchmark #12 to 14 - quick-sort in virtual memory.
 *   @author  Josef.Pelikan@mff.cuni.cz
 *   @version 0.007 (2001/06/16)
 *   @since   0.007
 */
public class BenchmarkQuickSort extends Benchmark {

    /**
     *  Initializing constructor.
     *   @param  ord Ordinal number of the test (valid values: 12 to 14).
     */
    public BenchmarkQuickSort ( int ord ) {
        if ( ord < 12 ) ord = 12;
        if ( ord > 14 ) ord = 14;
        order = ord;
        ok = false;
    }

    /** Ordinal number of the test. */
    protected int order;

    /** Array sizes. */
    protected final static int size[] = { 8<<20, 32<<20, 128<<20 };

    /** Sorting was successful. */
    protected boolean ok;

    /**
     *  Test (benchmark) ordinal number.
     *   @return Ordinal number of the test.
     */
    public int testNumber () {
        return order;
    }

    /**
     *  The benchmark algorithm itself. Needs not be re-entrant but can be iterated.
     */
    protected void test () {
        ok = false;
        int len = size[order-12];
        double[] a = new double[len];
        RandomJames rnd = new RandomJames();
        int i;
        for ( i = 0; i < len; )
            a[i++] = rnd.uniformNumber();
        QuickSortDouble.sort(a,0,len);
        for ( i = 0; i < len - 1; i++ )
            if ( a[i] > a[i+1] ) return;
        ok = true;
    }

    /**
     *  Result string of the test. Should be called after the <code>runTest()</code>
     *  was finished.
     *   @return Result of the test.
     */
    public String testResult () {
        return( "Quick-sort in virtual memory: " + (ok ? "OK" : "failed") +
                ", double[" + (size[order-12]>>20) + "M]" );
    }

}
