/** @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.3 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2004-08-06 22:34:05 $
 *
 *  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,"psVectorSortIndex", "Create vectors");
    in = psVectorAlloc(5, PS_TYPE_F32);
    in->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, "psVectorSortIndex", "Create vectors", true);


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

    // Test D - Verify the output vector is of type psU32
    printPositiveTestHeader(stdout,"psVectorSortIndex", "Verify output vector type");
    if(out->type.type != PS_TYPE_U32) {
        printf("ERROR: output vector is of type %d\n", out->type.type);
    }
    printFooter(stdout, "psVectorSortIndex", "Verify output vector type", true);

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

}
