Homework/HW09/Sort.cpp
void testSort(int rawArray[], int sortedArray[], unsigned long size,
              unsigned tests, timingSummary &timing)
{
    //Declare necessary variables and check the allocation as needed.
    timeval before, after;
    double *rawTiming = new (nothrow) double[tests];
    testAllocation(rawTiming);

    //Start the testing loop.
    cout << "\nDual Pivot Quick Sort - " << size << " Elements - " << tests << " Tests\n";
    for (unsigned test = 0; test < tests; ++test)
    {
        //Reset the sorted array prior to every test
        for (unsigned long element = 0; element < size; ++element)
            sortedArray[element] = rawArray[element];

        //Get the current time.
        gettimeofday(&before, 0);

        //Sort that array!
        dualPivotQuickSort(sortedArray, 0, size - 1, 3);

        //Get the elapsed time.
        gettimeofday(&after, 0);
        
        //Store the elapsed time after mathing it.
        rawTiming[test] = (double)((double)after.tv_sec +
                                   (double)after.tv_usec / (1000 * 1000)) -
                                   (double)((double)before.tv_sec +
                                   (double)before.tv_usec / (1000 * 1000));
    }

    //Set the default values of best, worst, and average.
    timing.best = timing.worst = timing.average = rawTiming[0];

    //Run through the array of the timings and figure out which one was the best and
    //which one was the worst.
    for (unsigned test = 1; test < tests; ++test)
    {
        if (timing.best>rawTiming[test])
            timing.best = rawTiming[test];
        if (timing.worst < rawTiming[test])
            timing.worst = rawTiming[test];
        timing.average += rawTiming[test];
    }

    //Get the total time and the average time.
    timing.total = timing.average;
    timing.average /= tests;
}
/****************************** testSort ***********************************************************
Action:         Applies a small testing framework for testing the desired sort, in this case the
                dual pivot quicksort.

Parameters:
IN:             int rawArray[], holds pointer to array with the raw data to sort.
IN:             int sortedArray[], holds pointer to array that will be sorted.
IN:             unsigned long size, holds the number of elements of the arrays.
IN:             unsigned tests, holds the number of tests to be run on the data.
OUT:            int sortedArray[], holds pointer to the array with the sorted data.
OUT:            timingSummary &timing, holds the timing summary of the tests.

Returns:        Nothing

Precondition:   Arrays should be allocated, and size should be the number of elements in each.
                The number of tests desired should be more than zero.
***************************************************************************************************/
testSort
Action:         Applies a small testing framework for testing the desired sort, in this case the
dual pivot quicksort.

int rawArray[], holds pointer to array with the raw data to sort.
IN:             int sortedArray[], holds pointer to array that will be sorted.
IN:             unsigned long size, holds the number of elements of the arrays.
IN:             unsigned tests, holds the number of tests to be run on the data.
OUT:            int sortedArray[], holds pointer to the array with the sorted data.
OUT:            timingSummary &timing, holds the timing summary of the tests.

Nothing

Arrays should be allocated, and size should be the number of elements in each.
The number of tests desired should be more than zero.
testSort Action : Applies a small testing framework for testing the desired sort in this case the dual pivot quicksort . int rawArray [] holds pointer to array with the raw data to sort . IN : int sortedArray [] holds pointer to array that will be sorted . IN : unsigned long size holds the number of elements of the arrays . IN : unsigned tests holds the number of tests to be run on the data . OUT : int sortedArray [] holds pointer to the array with the sorted data . OUT : timingSummary &timing holds the timing summary of the tests . Nothing Arrays should be allocated and size should be the number of elements in each . The number of tests desired should be more than zero .
void testSort(int rawArray[], int sortedArray[], unsigned long size,
              unsigned tests, timingSummary &timing)
{
    timeval before, after;
    double *rawTiming = new (nothrow) double[tests];
    testAllocation(rawTiming);
    cout << "\nDual Pivot Quick Sort - " << size << " Elements - " << tests << " Tests\n";
    for (unsigned test = 0; test < tests; ++test)
    {
        for (unsigned long element = 0; element < size; ++element)
            sortedArray[element] = rawArray[element];
        gettimeofday(&before, 0);
        dualPivotQuickSort(sortedArray, 0, size - 1, 3);
        gettimeofday(&after, 0);
        rawTiming[test] = (double)((double)after.tv_sec +
                                   (double)after.tv_usec / (1000 * 1000)) -
                                   (double)((double)before.tv_sec +
                                   (double)before.tv_usec / (1000 * 1000));
    }
    timing.best = timing.worst = timing.average = rawTiming[0];
    for (unsigned test = 1; test < tests; ++test)
    {
        if (timing.best>rawTiming[test])
            timing.best = rawTiming[test];
        if (timing.worst < rawTiming[test])
            timing.worst = rawTiming[test];
        timing.average += rawTiming[test];
    }
    timing.total = timing.average;
    timing.average /= tests;
}
void testSort ( int rawArray [ ] , int sortedArray [ ] , unsigned long size , unsigned tests , timingSummary & timing ) { timeval before , after ; double * rawTiming = new ( nothrow ) double [ tests ] ; testAllocation ( rawTiming ) ; cout << " \n " << size << " " << tests << " \n " ; for ( unsigned test = 0 ; test < tests ; ++ test ) { for ( unsigned long element = 0 ; element < size ; ++ element ) sortedArray [ element ] = rawArray [ element ] ; gettimeofday ( & before , 0 ) ; dualPivotQuickSort ( sortedArray , 0 , size - 1 , 3 ) ; gettimeofday ( & after , 0 ) ; rawTiming [ test ] = ( double ) ( ( double ) after . tv_sec + ( double ) after . tv_usec / ( 1000 * 1000 ) ) - ( double ) ( ( double ) before . tv_sec + ( double ) before . tv_usec / ( 1000 * 1000 ) ) ; } timing . best = timing . worst = timing . average = rawTiming [ 0 ] ; for ( unsigned test = 1 ; test < tests ; ++ test ) { if ( timing . best > rawTiming [ test ] ) timing . best = rawTiming [ test ] ; if ( timing . worst < rawTiming [ test ] ) timing . worst = rawTiming [ test ] ; timing . average += rawTiming [ test ] ; } timing . total = timing . average ; timing . average /= tests ; }
testSort
Action:         Applies a small testing framework for testing the desired sort, in this case the
dual pivot quicksort.
testSort Action : Applies a small testing framework for testing the desired sort in this case the dual pivot quicksort .
//Declare necessary variables and check the allocation as needed. //Start the testing loop. //Reset the sorted array prior to every test //Get the current time. //Sort that array! //Get the elapsed time. //Store the elapsed time after mathing it. //Set the default values of best, worst, and average. //Run through the array of the timings and figure out which one was the best and //which one was the worst. //Get the total time and the average time.