IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 7, 2004, 3:58:03 PM (22 years ago)
Author:
harman
Message:

Added more unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/dataManip/tst_psMatrix07.c

    r831 r908  
    55 *  This test driver contains the following tests for psMatrix test point 7:
    66 *     A)  Create input and output images and vectors
    7  *     B)  Convert matrix to vector
    8  *     C)  Convert vector to matrix
    9  *     D)  Free input and output images and vectors
     7 *     B)  Convert matrix to PS_DIMEN_VECTOR vector
     8 *     C)  Attempt to use null image input argument
     9 *     D)  Convert matrix to PS_DIMEN_TRANSV vector
     10 *     E)  Improper image size
     11 *     F)  Convert PS_DIMEN_VECTOR vector to matrix
     12 *     G)  Attempt to use null input vector argument
     13 *     H)  Convert PS_DIMEN_TRANSV vector to matrix
     14 *     I)  Free input and output images and vectors
    1015 *
    1116 *  @author  Ross Harman, MHPCC
    1217 *
    13  *  @version $Revision: 1.2 $  $Name: not supported by cvs2svn $
    14  *  @date  $Date: 2004-06-02 23:29:39 $
     18 *  @version $Revision: 1.3 $  $Name: not supported by cvs2svn $
     19 *  @date  $Date: 2004-06-08 01:56:35 $
    1520 *
    1621 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2227
    2328#define PRINT_MATRIX(IMAGE)                         \
    24 for(int i=0; i<IMAGE->numRows; i++) {           \
    25     for(int j=0; j<IMAGE->numCols; j++) {       \
    26         printf("%f ", IMAGE->data.F64[i][j]);   \
    27     }                                          \
    28     printf("\n");                              \
     29for(int i=0; i<IMAGE->numRows; i++) {               \
     30    for(int j=0; j<IMAGE->numCols; j++) {           \
     31        printf("%f ", IMAGE->data.F64[i][j]);       \
     32    }                                               \
     33    printf("\n");                                   \
    2934}
    3035
    3136#define PRINT_VECTOR(VECTOR)                        \
    32 for(int i=0; i<VECTOR->n; i++) {               \
    33     printf("%f\n", VECTOR->data.F64[i]);          \
     37for(int i=0; i<VECTOR->n; i++) {                    \
     38    printf("%f\n", VECTOR->data.F64[i]);            \
    3439}
    3540
     
    3944{
    4045    psVector *v1 = NULL;
     46    psVector *tempVector = NULL;
     47    psImage *tempImage = NULL;
    4148    psImage *m1 = NULL;
    4249    psVector *v2 = NULL;
    4350    psImage *m2 = NULL;
     51    psImage *m3 = NULL;
     52    psImage *m4 = NULL;
     53    psImage *badImage = NULL;
    4454
    4555
     
    5060    v2 = (psVector*)psVectorAlloc(3, PS_TYPE_F64);
    5161    m2 = (psImage*)psImageAlloc(1, 3, PS_TYPE_F64);
     62    m3 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64);
     63    m4 = (psImage*)psImageAlloc(3, 1, PS_TYPE_F64);
     64    badImage = (psImage*)psImageAlloc(2, 2, PS_TYPE_F64);
    5265    m1->data.F64[0][0] = 0.0;
    5366    m1->data.F64[1][0] = 1.0;
     
    5770    v2->data.F64[2] = 2.0;
    5871    v2->n = 3;
     72    m4->data.F64[0][0] = 0.0;
     73    m4->data.F64[0][1] = 1.0;
     74    m4->data.F64[0][2] = 2.0;
    5975    PRINT_MATRIX(m1);
     76    printf("\n");
     77    PRINT_MATRIX(m4);
    6078    printf("\n");
    6179    PRINT_VECTOR(v2);
     
    6381
    6482
    65     // Test B - Convert matrix to vector
    66     printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to vector");
    67     psMatrixToVector(v1, m1);
     83    // Test B - Convert matrix to PS_DIMEN_VECTOR vector
     84    printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector");
     85    tempVector = v1;
     86    v1 = psMatrixToVector(v1, m1);
    6887    PRINT_VECTOR(v1);
    69     printFooter(stdout, "psMatrix", "Calculate Eigenvectors", true);
     88    if(v1->type.dimen != PS_DIMEN_VECTOR) {
     89        printf("Error: Resulting image is not PS_DIMEN_VECTOR\n");
     90    } else if(v1 != tempVector) {
     91        printf("Error: Return pointer not equal to output argument pointer\n");
     92    }
     93    printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_VECTOR vector", true);
    7094
    7195
    72     // Test C - Convert vector to matrix
    73     printPositiveTestHeader(stdout, "psMatrix", "Convert vector to matrix");
    74     psVectorToMatrix(m2, v2);
    75     PRINT_MATRIX(m2);
    76     printFooter(stdout, "psMatrix", "Convert vector to matrix", true);
     96    // Test C - Attempt to use null image input argument
     97    printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null image input argument",
     98                            "Invalid operation: inImage or its data is NULL.", 0);
     99    v1 = psMatrixToVector(v1, NULL);
     100    printFooter(stdout, "psMatrix", "Attempt to use null image input argument", true);
    77101
    78102
    79     // Test D - Free input and output images
     103    // Test D - Convert matrix to PS_DIMEN_TRANSV vector
     104    printPositiveTestHeader(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector");
     105    v1->type.dimen = PS_DIMEN_TRANSV;
     106    psMatrixToVector(v1, m4);
     107    PRINT_VECTOR(v1);
     108    if(v1->type.dimen != PS_DIMEN_TRANSV) {
     109        printf("Error: Resulting image is not PS_DIMEN_TRANSV\n");
     110    } else if(v1 != tempVector) {
     111        printf("Error: Return pointer not equal to output argument pointer\n");
     112    }
     113    printFooter(stdout, "psMatrix", "Convert matrix to PS_DIMEN_TRANSV vector", true);
     114
     115
     116    // Test E - Improper image size
     117    printNegativeTestHeader(stdout,"psMatrix", "Improper image size",
     118                            "Image does not have dim with 1 col or 1 row: (2 x 2).", 0);
     119    psMatrixToVector(v1, badImage);
     120    printFooter(stdout, "psMatrix", "Improper image size", true);
     121
     122
     123    // Test F - Convert PS_DIMEN_VECTOR vector to matrix
     124    printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix");
     125    tempImage = m2;
     126    m2 = psVectorToMatrix(m2, v2);
     127    PRINT_MATRIX(m2);
     128    if(m2->type.dimen != PS_DIMEN_IMAGE) {
     129        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     130    } else if(m2 != tempImage) {
     131        printf("Error: Return pointer not equal to output argument pointer\n");
     132    }
     133    printFooter(stdout, "psMatrix", "Convert PS_DIMEN_VECTOR vector to matrix", true);
     134
     135
     136    // Test G - Attempt to use null input vector argument
     137    printNegativeTestHeader(stdout,"psMatrix", "Attempt to use null input vector argument",
     138                            "Invalid operation: inVector or its data is NULL.", 0);
     139    psVectorToMatrix(m2, NULL);
     140    printFooter(stdout, "psMatrix", "Attempt to use null input vector argument", true);
     141
     142
     143    // Test H - Convert PS_DIMEN_TRANSV vector to matrix
     144    printPositiveTestHeader(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix");
     145    v2->type.dimen = PS_DIMEN_TRANSV;
     146    tempImage = m3;
     147    psVectorToMatrix(m3, v2);
     148    PRINT_MATRIX(m3);
     149    if(m3->type.dimen != PS_DIMEN_IMAGE) {
     150        printf("Error: Resulting image is not PS_DIMEN_IMAGE\n");
     151    } else if(m3 != tempImage) {
     152        printf("Error: Return pointer not equal to output argument pointer\n");
     153    }
     154    printFooter(stdout, "psMatrix", "Convert PS_DIMEN_TRANSV vector to matrix", true);
     155
     156
     157    // Test I - Free input and output images
    80158    printPositiveTestHeader(stdout, "psMatrix", "Free input and output images and vectors");
    81159    psImageFree(m1);
     
    83161    psImageFree(m2);
    84162    psVectorFree(v2);
     163    psImageFree(m3);
     164    psImageFree(m4);
     165    psImageFree(badImage);
    85166    psMemCheckLeaks(0, NULL, stdout);
    86167    int nBad = psMemCheckCorruption(0);
Note: See TracChangeset for help on using the changeset viewer.