/** @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.2 $  $Name: not supported by cvs2svn $
 *  @date  $Date: 2007-01-24 22:14:48 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
 *
 */

#include <pslib.h>

#include "tap.h"
#include "pstap.h"


psS32 main(psS32 argc,
           char* argv[])
{
    plan_tests(2);

    psVector *in = NULL;
    psVector *out = NULL;
    psVector *in2 = NULL;
    psVector *out2 = NULL;

    // Test A - Create float vectors
    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]);
    }


    // Test B - Sort input float vector and put results into output float vector
    out = psVectorSort(out, in);

    // Test C - Create float vector and double vector
    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]);
    }

    // Test D - Attempt to sort vectors with output of different type should create error
    out2 = psVectorSort(out2, in2);

    // Test C - Free float vectors
    psFree(in);
    psFree(in2);
    psFree(out);
    psFree(out2);
    psS32 nLeaks = psMemCheckLeaks(0, NULL, stdout, false);
    ok(!nLeaks, "Found %d memory leaks\n", nLeaks);
    psS32 nBad = psMemCheckCorruption(stderr, false);
    ok(!nBad, "Found %d bad memory blocks\n", nBad);
}
