/*****************************************************************************
    This routine must ensure that PS_STAT_NVALUES is correctly computed
    by the procedure psVectorStats().
 
    Note: The NVALUES stat was removed from the IfA requirements spec.  So,
    this test is no longer in use.
 *****************************************************************************/
#include <stdio.h>
#include "pslib.h"
#include "psTest.h"
#define N1 1029
#define N ((4 * N1) + 1)

psS32 main()
{
    psStats *myStats    = NULL;
    psS32 testStatus      = true;
    psS32 i               = 0;
    psVector *myVector  = NULL;
    psVector *maskVector= NULL;

    /*************************************************************************/
    /*  Allocate and initialize data structures                      */
    /*************************************************************************/
    myStats = psStatsAlloc(PS_STAT_NVALUES);
    myVector = psVectorAlloc(N, PS_TYPE_F32);
    myVector->n = N;
    maskVector = psVectorAlloc(N, PS_TYPE_U8);
    maskVector->n = N;

    // Set the appropriate values for the vector data.
    for (i=0;i<N;i++) {
        myVector->data.F32[i] = (float) i;
    }

    // Set the mask vector and calculate the expected maximum.
    for (i=0;i<N;i++) {
        if (i < (N/2)) {
            maskVector->data.U8[i] = 0;
        } else {
            maskVector->data.U8[i] = 1;
        }
    }

    /*************************************************************************/
    /*  Call psVectorStats() with no vector mask.                    */
    /*************************************************************************/
    printPositiveTestHeader(stdout,
                            "psStats functions",
                            "PS_STAT_NVALUES");

    myStats = psVectorStats(myStats, myVector, NULL, 0);

    printf("Called psVectorStats() on a vector with no elements masked.\n");
    printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
           N, myStats->nValues);
    if (myStats->nValues == N) {
        testStatus = true;
    } else {
        testStatus = false;
    }

    /*************************************************************************/
    /*  Call psVectorStats() with vector mask.                       */
    /*************************************************************************/
    myStats = psVectorStats(myStats, myVector, maskVector, 1);
    printf("Called psVectorStats() on a vector with last N/2 elements masked.\n");
    printf("The expected nvalues was %d.  The calculated nvalues was %d.\n",
           N/2, myStats->nValues);
    if (myStats->nValues == N/2) {
        testStatus = true;
    } else {
        testStatus = false;
    }

    printFooter(stdout,
                "psHash functions",
                "psHashAlloc()",
                testStatus);

    return (!testStatus);
}
