/** @file  tst_psVectorSort_01.c
 *
 *  @brief Test driver for psVectorSort functions
 *
 *  This test driver contains the following tests for psVectorSort test point 1:
 *     A)  Create float vectors
 *     B)  Sort input float vector and put results into output float vector
 *     C)  Free float 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;
    psVector *tempVec = NULL;


    // Test A - Create float vectors
    printPositiveTestHeader(stdout,"psVectorSort", "Create float vectors");
    in = psVectorAlloc(7, PS_TYPE_F32);
    in->n = 7;
    out = psVectorAlloc(7, PS_TYPE_F32);
    out->n = 7;
    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;
    in->data.F32[5] = 5.0f;
    in->data.F32[6] = -20.0f;
    for(int i=0; i<7; i++) {
        printf("vec[%d] = %f\n", i, in->data.F32[i]);
    }
    printFooter(stdout, "psVectorSort", "Create float vectors", true);


    // Test B - Sort input float vector and put results into output float vector
    printPositiveTestHeader(stdout,"psVectorSort", "Sort float vector");
    tempVec = out;
    out = psVectorSort(out, in);
    for(int i=0; i<7; i++) {
        printf("vec[%d] = %f\n", i, out->data.F32[i]);
    }
    if(out != tempVec) {
        printf("Error: Return pointer not equal to output argument pointer\n");
    }
    printFooter(stdout, "psVectorSort", "Sort float vector", true);


    // Test C - Sort input float vector into itself
    printPositiveTestHeader(stdout,"psVectorSort", "Sort input float vector into itself");
    in = psVectorSort(in, in);
    for(int i=0; i<7; i++) {
        printf("vec[%d] = %f\n", i, out->data.F32[i]);
    }
    printFooter(stdout, "psVectorSort", "Sort input float vector into itself", true);


    // Test D - Free float vectors
    printPositiveTestHeader(stdout,"psVectorSort", "Free float 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 float vectors", true);

    return 0;
}
