/** @file  tst_psVectorSort_02.c
 *
 *  @brief Test driver for psVectorSort functions
 *
 *  This test driver contains the following tests for psVectorSort test point 2:
 *     A)  Create vectors
 *     B)  Sort integer vector of indices based on pre-sort order of floating point vector
 *     C)  Free vectors
 *
 *  @author  Ross Harman, MHPCC
 *
 *  @version $Revision: 1.1 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2004-07-15 23:52:34 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */

#include "pslib.h"
#include "psTest.h"

int main(int argc,
         char* argv[])
{
    psVector *in = NULL;
    psVector *out = NULL;


    // Test A - Create float vectors
    printPositiveTestHeader(stdout,"psVectorSort", "Create vectors");
    in = psVectorAlloc(5, PS_TYPE_F32);
    in->n = 5;
    out = psVectorAlloc(5, PS_TYPE_F32);
    out->n = 5;
    in->data.F32[0] = 7.0f;
    in->data.F32[1] = 9.0f;
    in->data.F32[2] = 3.0f;
    in->data.F32[3] = 1.0f;
    in->data.F32[4] = 5.0f;
    for(int i=0; i<5; i++) {
        printf("arr[%d] = %f\n", i, in->data.F32[i]);
    }
    printFooter(stdout, "psVectorSort", "Create vectors", true);


    // Test B - Sort integer vector of indices based on pre-sort order of floating point vector
    printPositiveTestHeader(stdout,"psVectorSort", "Create sorted index vector");
    out = psVectorSortIndex(out, in);
    for(int i=0; i<5; i++) {
        printf("arr[%d] = %d\n", i, out->data.S32[i]);
    }
    printFooter(stdout, "psVectorSort", "Create sorted index vector", true);


    // Test C - Free vectors
    printPositiveTestHeader(stdout,"psVectorSort", "Free vectors");
    psFree(in);
    psFree(out);
    psMemCheckLeaks(0, NULL, stdout);
    int nBad = psMemCheckCorruption(0);
    if(nBad) {
        printf("ERROR: Found %d bad memory blocks\n", nBad);
    }
    printFooter(stdout, "psVectorSort", "Free vectors", true);

}
