Index: trunk/psLib/test/dataManip/tst_psRandom.c
===================================================================
--- trunk/psLib/test/dataManip/tst_psRandom.c	(revision 3682)
+++ trunk/psLib/test/dataManip/tst_psRandom.c	(revision 4082)
@@ -34,23 +34,45 @@
 psS32 testStatus = true;
 
-psS32 t00()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
-
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc()");
+static psS32 testRandomAlloc(void);
+static psS32 testRandomUniform(void);
+static psS32 testRandomGaussian(void);
+static psS32 testRandomPoisson(void);
+static psS32 testRandomResetUniform(void);
+static psS32 testRandomResetGaussian(void);
+static psS32 testRandomResetPoisson(void);
+
+testDescription tests[] = {
+                              {testRandomAlloc,000,"psRandomAlloc",0,false},
+                              {testRandomUniform,000,"psRandomUniform",0,false},
+                              {testRandomGaussian,000,"psRandomGaussian",0,false},
+                              {testRandomPoisson,000,"psRandomPoisson",0,false},
+                              {testRandomResetUniform,000,"psRandomReset",0,false},
+                              {testRandomResetGaussian,000,"psRandomReset",0,false},
+                              {testRandomResetPoisson,000,"psRandomReset",0,false},
+                              {NULL}
+                          };
+
+psS32 main(psS32 argc, char* argv[])
+{
+    if(!runTestSuite(stderr,"psRandom",tests,argc,argv)) {
+        return 1;
+    }
+
+    return 0;
+}
+
+psS32 testRandomAlloc(void)
+{
+    psRandom *myRNG = NULL;
 
     // Valid type allocation
     myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
     if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
     }
     if (myRNG->type != PS_RANDOM_TAUS) {
-        psError(PS_ERR_UNKNOWN,true,"Did not have the expected type");
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",myRNG->type,PS_RANDOM_TAUS);
+        return 2;
     }
     psFree(myRNG);
@@ -61,10 +83,10 @@
     psLogSetDestination("dest:stderr");
     if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 3;
     }
     if (myRNG->type != PS_RANDOM_TAUS) {
-        psError(PS_ERR_UNKNOWN,true,"Did not have the expected type");
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"Type %d not as expected %d",myRNG->type,PS_RANDOM_TAUS);
+        return 4;
     }
     psFree(myRNG);
@@ -75,5 +97,5 @@
     if (myRNG != NULL) {
         psError(PS_ERR_UNKNOWN,true,"Did not return NULL for invalid type");
-        testStatus = false;
+        return 5;
     }
 
@@ -82,60 +104,43 @@
     if(myRNG == NULL) {
         psError(PS_ERR_UNKNOWN,true,"Did not return allocated psRandom");
-        testStatus = false;
-    }
-    psFree(myRNG);
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        printf("ERROR: Memory Leaks! (%d leaks)", memLeaks);
-        testStatus = false;
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t01()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+        return 6;
+    }
+    psFree(myRNG);
+
+    return 0;
+}
+
+psS32 testRandomUniform(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc() and psRandomUniform()");
-
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
-
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Initialize vector data with random number
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         rans->data.F64[i] = psRandomUniform(myRNG);
-        //        printf("%.2f\n", rans->data.F64[i]);
-    }
-    stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Mean is %.2f\n", stats->sampleMean);
+    }
+    // Perform vector stats on random data (mean, stdev)
+    stats = psVectorStats(stats, rans, NULL, NULL, 0);
     stats->options = PS_STAT_SAMPLE_STDEV;
     stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Standard deviation is %.2f\n", stats->sampleStdev);
+    // Verify mean and stdev
     if ((fabs(stats->sampleMean - UNIFORM_MEAN) / UNIFORM_MEAN) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() mean is %.2f, should be %.2f\n", stats->sampleMean, UNIFORM_MEAN);
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"psRandomUniform mean is %.2f, should be %.2f",
+                stats->sampleMean, UNIFORM_MEAN);
+        return 2;
     }
     if ((fabs(stats->sampleStdev - UNIFORM_STDEV) / UNIFORM_STDEV) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() stdev is %.2f, should be %.2f\n", stats->sampleStdev, UNIFORM_STDEV);
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
+        psError(PS_ERR_UNKNOWN,true,"psRandomUniform stdev is %.2f, should be %.2f",
+                stats->sampleStdev, UNIFORM_STDEV);
+        return 3;
+    }
+
     psFree(myRNG);
     psFree(rans);
@@ -145,58 +150,44 @@
     if(psRandomUniform(NULL) != 0) {
         psError(PS_ERR_UNKNOWN,true,"Did not return zero for null psRandom");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc() and psRandomUniform()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t02()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+        return 4;
+    }
+
+    return 0;
+}
+
+psS32 testRandomGaussian(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc() and psRandomGaussian()");
-
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
-
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Initialize vector with random data
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         rans->data.F64[i] = psRandomGaussian(myRNG);
-        //        printf("%.2f\n", rans->data.F64[i]);
-    }
-    stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Mean is %.2f\n", stats->sampleMean);
+    }
+
+    // Perform vector stats on data (mean, stdev)
+    stats = psVectorStats(stats, rans, NULL, NULL, 0);
     stats->options = PS_STAT_SAMPLE_STDEV;
     stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Standard deviation is %.2f\n", stats->sampleStdev);
+
+    // Verify statistics
     if ((fabs(stats->sampleMean - GAUSSIAN_MEAN) / 1.0) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() mean is %.2f, should be %.2f\n", stats->sampleMean, GAUSSIAN_MEAN);
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"psRandomGaussian mean is %.2f, should be %.2f",
+                stats->sampleMean, GAUSSIAN_MEAN);
+        return 2;
     }
     if ((fabs(stats->sampleStdev - GAUSSIAN_STDEV) / GAUSSIAN_STDEV) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() stdev is %.2f, should be %.2f\n", stats->sampleStdev, GAUSSIAN_STDEV);
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
+        psError(PS_ERR_UNKNOWN,true,"psRandomGaussian stdev is %.2f, should be %.2f",
+                stats->sampleStdev, GAUSSIAN_STDEV);
+        return 3;
+    }
+
     psFree(myRNG);
     psFree(rans);
@@ -206,59 +197,42 @@
     if(psRandomGaussian(NULL) != 0) {
         psError(PS_ERR_UNKNOWN,true,"Did not return zero for null psRandom");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc() and psRandomGaussian()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t03()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+        return 4;
+    }
+
+    return 0;
+}
+
+psS32 testRandomPoisson(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psStats *stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc() and psRandomPoisson()");
-
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
-
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Initialize vector with random data
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         rans->data.F64[i] = psRandomPoisson(myRNG, POISSON_MEAN);
-        //        printf("%.2f\n", rans->data.F64[i]);
-    }
-    stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Mean is %.2f\n", stats->sampleMean);
+    }
+
+    // Perform statistics on data
+    stats = psVectorStats(stats, rans, NULL, NULL, 0);
     stats->options = PS_STAT_SAMPLE_STDEV;
     stats = psVectorStats(stats, rans, NULL, NULL, 0);
-    printf("Standard deviation is %.2f\n", stats->sampleStdev);
     if ((fabs(stats->sampleMean - POISSON_MEAN) / POISSON_MEAN) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() mean is %.2f, should be %.2f\n", stats->sampleMean, POISSON_MEAN);
-        testStatus = false;
+        psError(PS_ERR_UNKNOWN,true,"psRandomPoisson mean is %.2f, should be %.2f",
+                stats->sampleMean, POISSON_MEAN);
+        return 2;
     }
     if ((fabs(stats->sampleStdev - POISSON_STDEV) / POISSON_STDEV) > ERROR_TOLERANCE) {
-        printf("ERROR: psRandomUniform() stdev is %.2f, should be %.2f\n", stats->sampleStdev, POISSON_STDEV);
-        testStatus = false;
-    }
-
-
-    psMemCheckCorruption(1);
+        psError(PS_ERR_UNKNOWN,true,"psRandomPoisson stdev is %.2f, should be %.2f",
+                stats->sampleStdev, POISSON_STDEV);
+        return 3;
+    }
+
     psFree(myRNG);
     psFree(rans);
@@ -268,38 +242,24 @@
     if(psRandomPoisson(NULL, POISSON_MEAN) != 0) {
         psError(PS_ERR_UNKNOWN,true,"Did not return zero for null psRandom");
-        testStatus = false;
-    }
-
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc() and psRandomPoisson()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t04()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+        return 4;
+    }
+
+    return 0;
+}
+
+psS32 testRandomResetUniform(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans00 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans01 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans02 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc(), psRandomReset(), and psRandomUniform()");
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Random reset
     psRandomReset(myRNG, SEED);
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
@@ -315,11 +275,12 @@
     }
 
+    // Verify reset to original seed produces same results
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         if (rans00->data.F64[i] != rans02->data.F64[i]) {
-            printf("ERROR: psRandomUniform() did not produce the same results with the same seed\n");
+            psError(PS_ERR_UNKNOWN,true,"psRandomUniform did not produce the same results with the same seed");
+            return i+1;
         }
     }
 
-    psMemCheckCorruption(1);
     psFree(myRNG);
     psFree(rans00);
@@ -337,35 +298,21 @@
     psRandomReset(NULL,SEED);
 
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc(), psRandomReset(), and psRandomUniform()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t05()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+    return 0;
+}
+
+psS32 testRandomResetGaussian(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans00 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans01 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans02 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc(), psRandomReset(), and psRandomGaussian()");
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Initialize random data in vectors
     psRandomReset(myRNG, SEED);
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
@@ -381,46 +328,34 @@
     }
 
+    // Verify data from original seed produces same data after reset
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         if (rans00->data.F64[i] != rans02->data.F64[i]) {
-            printf("ERROR: psRandomGaussian() did not produce the same results with the same seed\n");
+            psError(PS_ERR_UNKNOWN,true,"psRandomGaussian did not produce the same results with the same seed");
+            return 2;
         }
     }
 
-    psMemCheckCorruption(1);
     psFree(myRNG);
     psFree(rans00);
     psFree(rans01);
     psFree(rans02);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc(), psRandomReset(), and psRandomGaussian()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 t06()
-{
-    psRandom *myRNG = NULL;
-    psS32 currentId = psMemGetId();
-    psS32 memLeaks = 0;
+
+    return 0;
+}
+
+psS32 testRandomResetPoisson(void)
+{
+    psRandom *myRNG = NULL;
     psVector *rans00 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans01 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
     psVector *rans02 = psVectorAlloc(NUM_DATA, PS_TYPE_F64);
 
-    printPositiveTestHeader(stdout,
-                            "psRandom functions",
-                            "psRandomAlloc(), psRandomReset(), and psRandomPoisson()");
-    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
-    if (myRNG == NULL) {
-        printf("ERROR: Could not allocate psRandom structure\n");
-        testStatus = false;
-    }
+    myRNG = psRandomAlloc(PS_RANDOM_TAUS, SEED);
+    if (myRNG == NULL) {
+        psError(PS_ERR_UNKNOWN,true,"Could not allocate psRandom structure");
+        return 1;
+    }
+
+    // Initialize vectors with random data
     psRandomReset(myRNG, SEED);
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
@@ -436,41 +371,18 @@
     }
 
+    // Verify the original seed produces same data after reset
     for (psS32 i = 0 ; i < NUM_DATA ; i++) {
         if (rans00->data.F64[i] != rans02->data.F64[i]) {
-            printf("ERROR: psRandomPoisson() did not produce the same results with the same seed\n");
+            psError(PS_ERR_UNKNOWN,true,"psRandomPoisson did not produce the same results with the same seed");
+            return 2;
         }
     }
 
-    psMemCheckCorruption(1);
     psFree(myRNG);
     psFree(rans00);
     psFree(rans01);
     psFree(rans02);
-    psMemCheckCorruption(1);
-    memLeaks = psMemCheckLeaks(currentId,NULL,stderr,false);
-    if (0 != memLeaks) {
-        psAbort(__func__,"Memory Leaks! (%d leaks)", memLeaks);
-    }
-
-    printFooter(stdout,
-                "psRandom functions",
-                "psRandomAlloc(), psRandomReset(), and psRandomPoisson()",
-                testStatus);
-
-    return(testStatus);
-}
-
-psS32 main()
-{
-    testStatus = true;
-
-    t00();
-    t01();
-    t02();
-    t03();
-    t04();
-    t05();
-    t06();
-
-    return(!testStatus);
-}
+
+    return 0;
+}
+
