/** @file  tst_psVectorSort_03.c
 *
 *  @brief Test driver for psVectorSort functions
 *
 *  This test driver contains the following tests for psVectorSort test point 3:
 *     A)  Create float vectors of different sizes
 *     B)  Attempt to sort vectors...should get errors
 *     C)  Create float vector and double vector
 *     D)  Attempt to sort vectors...should get errors
 *     E)  Free float, double vectors
 *
 *  @author  Ross Harman, MHPCC
 *
 *  @version $Revision: 1.6 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2004-11-22 21:07:42 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 *
 */

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

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

    // Test A - Create float vectors
    printPositiveTestHeader(stdout,"psVectorSort", "Create float vectors of different sizes");
    in = psVectorAlloc(5, PS_TYPE_F32);
    in->n = 5;
    out = psVectorAlloc(6, PS_TYPE_F32);
    out->n = 6;
    in->n = 5;
    for(psS32 i=0; i<5; i++) {
        printf("arr[%d] = %f\n", i, in->data.F32[i]);
    }
    printFooter(stdout, "psVectorSort", "Create float vectors of different sizes", true);


    // Test B - Sort input float vector and put results into output float vector
    printNegativeTestHeader(stdout,"psVectorSort", "Sort float vector",
                            "Input and output vector sizes are not equal", 0);
    out = psVectorSort(out, in);
    printFooter(stdout, "psVectorSort", "Sort float vector", true);

    // Test C - Create float vector and double vector
    printPositiveTestHeader(stdout,"psVectorSort","Create float & double vectors of same size");
    in2 = psVectorAlloc(5, PS_TYPE_F32);
    in2->n = 5;
    out2 = psVectorAlloc(5, PS_TYPE_F64);
    out2->n = 5;
    for(psS32 j=0; j<5; j++) {
        printf("vec[%d] = %f\n", j, in2->data.F32[j]);
    }
    printFooter(stdout, "psVectorSort", "Create float and double vectors same size", true);

    // Test D - Attempt to sort vectors with output of different type should create error
    printNegativeTestHeader(stdout,"psVectorSort", "Sort F32/F64 vector",
                            "Input and output vector different types", 0);
    out2 = psVectorSort(out2, in2);
    printFooter(stdout, "psVectorSort", "Sort float vector", true);

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

}
