IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7779


Ignore:
Timestamp:
Jun 30, 2006, 6:39:49 PM (20 years ago)
Author:
jhoblitt
Message:

add psVectorExtend() tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/mathtypes/tap_psVector.c

    r7778 r7779  
    55int main (void)
    66{
    7     plan_tests(39);
    8 
    9     {
    10         psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
    11 
    12         diag("psVector Alloc tests");
     7    plan_tests(50);
     8
     9    diag("psVectorAlloc() tests");
     10
     11    {
     12        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     13
    1314        ok(psVec != NULL, "psVector successfully allocated");
    1415        ok(psVec->nalloc == 5, "Vector size = %ld", psVec->nalloc);
     
    4445    }
    4546
     47    diag("psVectorRealloc() tests");
     48
    4649    {
    4750        // create new psVector
    4851        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
    49 
    50         diag("psVector Realloc tests");
    51         ok (psVec != NULL, "test vector allocated");
    5252
    5353        // generate first part of vector
     
    5959        // Test C - Reallocate S32 vector bigger
    6060        psVec = psVectorRealloc(psVec,10);
    61         ok (psVec != NULL, "test vector reallocated to bigger size");
    62         ok (psVec->nalloc == 10, "Vector size = %ld", psVec->nalloc);
    63         ok (psVec->n == 5, "Vector population = %ld", psVec->n);
    64         ok (psVec->type.type == PS_TYPE_S32, "Vector type = %d", psVec->type.type);
    65         ok (psVec->type.dimen == PS_DIMEN_VECTOR, "Vector dimen = %d", psVec->type.dimen);
     61        ok(psVec != NULL, "test vector reallocated to bigger size");
     62        ok(psVec->nalloc == 10, "Vector size = %ld", psVec->nalloc);
     63        ok(psVec->n == 5, "Vector population = %ld", psVec->n);
     64        ok(psVec->type.type == PS_TYPE_S32, "Vector type = %d", psVec->type.type);
     65        ok(psVec->type.dimen == PS_DIMEN_VECTOR, "Vector dimen = %d", psVec->type.dimen);
    6666
    6767        // generate test data values
     
    7676        }
    7777
     78        psFree(psVec);
     79    }
     80
     81    {
    7882        // Test D - Reallocate S32 vector smaller
     83        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     84        psVec->n = 5;
    7985        psVec = psVectorRealloc(psVec,3);
    80         ok (psVec != NULL, "test vector reallocated to smaller size");
    81         ok (psVec->nalloc == 3, "Vector size = %ld", psVec->nalloc);
    82         ok (psVec->n == 3, "Vector population = %ld", psVec->n);
     86
     87        ok(psVec != NULL, "test vector reallocated to smaller size");
     88        ok(psVec->nalloc == 3, "Vector size = %ld", psVec->nalloc);
     89        ok(psVec->n == 3, "Vector population = %ld", psVec->n);
    8390
    8491        // test data values
     
    8996        // reallocate to 0 length
    9097        psVec = psVectorRealloc(psVec,0);
    91         ok (psVec != NULL, "test vector reallocated to zero length");
    92         ok (psVec->nalloc == 0, "Vector size = %ld", psVec->nalloc);
    93         ok (psVec->n == 0, "Vector population = %ld", psVec->n);
     98        ok(psVec != NULL, "test vector reallocated to zero length");
     99        ok(psVec->nalloc == 0, "Vector size = %ld", psVec->nalloc);
     100        ok(psVec->n == 0, "Vector population = %ld", psVec->n);
    94101
    95102        // Test E - Free S32 vector
     
    99106
    100107    {
    101         psVector* vecBogus = psVectorRealloc(NULL, 6);
    102 
    103         ok(vecBogus == NULL, "psVectorAlloc() doesn't not accept bogus type");
     108        psVector *vecBogus = psVectorAlloc(5, PS_TYPE_S32);
     109        vecBogus = psVectorRealloc(NULL, 6);
     110
     111        ok(vecBogus == NULL, "psVectorRealloc() doesn't not accept bogus type");
    104112        psErr *err = psErrorLast();
    105113
    106         skip_start(err == NULL, 2, "Skipping 2 tests because psVectorAlloc() didn't fail as expect");
     114        skip_start(err == NULL, 2, "Skipping 2 tests because psVectorRealloc() didn't fail as expect");
    107115        ok(strstr(err->name, "psVectorRealloc"), "alloc failure - got error name %s", err->name);
    108116        ok(err->code == PS_ERR_BAD_PARAMETER_NULL, "alloc failure - got error code %d", err->code);
     
    110118
    111119        psFree(vecBogus);
    112 
    113         return exit_status();
    114     }
     120    }
     121
     122    diag("psVectorExtend() tests");
     123
     124    {
     125        // create new psVector
     126        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     127        psVec->n = 0;
     128        psVec = psVectorExtend(psVec, 0, 2);
     129
     130        ok(psVec != NULL, "test vector extended");
     131        ok(psVec->nalloc == 5, "Vector size = %ld", psVec->nalloc);
     132        ok(psVec->n == 2, "Vector population = %ld", psVec->n);
     133
     134        psFree(psVec);
     135    }
     136
     137    {
     138        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     139        psVec = psVectorExtend(psVec, 0, 2);
     140        psVec = psVectorExtend(psVec, 0, 2);
     141
     142        ok(psVec != NULL, "test vector extended");
     143        ok(psVec->nalloc == 5, "Vector size = %ld", psVec->nalloc);
     144        ok(psVec->n == 4,"Vector population = %ld", psVec->n);
     145
     146        psFree(psVec);
     147    }
     148
     149    {
     150        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     151        psVec = psVectorExtend(psVec, 0, 2);
     152        psVec = psVectorExtend(psVec, 0, 2);
     153        psVec = psVectorExtend(psVec, 0, -2);
     154
     155        ok(psVec != NULL, "test vector extended");
     156        ok(psVec->nalloc == 5 ,"Vector size = %ld", psVec->nalloc);
     157        ok(psVec->n == 2, "Vector population = %ld", psVec->n);
     158
     159        psFree(psVec);
     160    }
     161
     162    {
     163        psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
     164        psVec = psVectorExtend(psVec, 0, 2);
     165        psVec = psVectorExtend(psVec, 0, 2);
     166        psVec = psVectorExtend(psVec, 0, -2);
     167        psVec = psVectorExtend(psVec, 0, -20);
     168
     169        ok(psVec != NULL, "test vector extended");
     170        ok(psVec->nalloc == 5, "Vector size = %ld", psVec->nalloc);
     171        ok(psVec->n == 0, "Vector population = %ld", psVec->n);
     172
     173        psFree(psVec);
     174    }
     175
     176    return exit_status();
    115177}
    116178
    117179# if 0
    118 
    119 psS32 testVectorExtend(void)
    120 {
    121     // create new psVector
    122     psVector *psVec = psVectorAlloc(5, PS_TYPE_S32);
    123     if (psVec == NULL) {
    124         fprintf(stderr,"ERROR: Return is NULL\n");
    125         return 1;
    126     }
    127 
    128     psVec->n = 0;
    129 
    130     psVec = psVectorExtend(psVec, 0, 2);
    131     if (psVec == NULL) {
    132         fprintf(stderr,"ERROR: Return is NULL\n");
    133         return 2;
    134     }
    135     if (psVec->nalloc != 5) { // no growth should occur
    136         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    137         return 3;
    138     }
    139     if (psVec->n != 2) {
    140         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    141         return 4;
    142     }
    143 
    144     psVec = psVectorExtend(psVec, 0, 2);
    145     if (psVec == NULL) {
    146         fprintf(stderr,"ERROR: Return is NULL\n");
    147         return 10;
    148     }
    149     if (psVec->nalloc != 15) { // growth should occur
    150         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    151         return 11;
    152     }
    153     if (psVec->n != 4) {
    154         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    155         return 12;
    156     }
    157 
    158     psVec = psVectorExtend(psVec, 0, -2);
    159     if (psVec == NULL) {
    160         fprintf(stderr,"ERROR: Return is NULL\n");
    161         return 20;
    162     }
    163     if (psVec->nalloc != 15) { // no growth
    164         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    165         return 21;
    166     }
    167     if (psVec->n != 2) {
    168         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    169         return 22;
    170     }
    171 
    172     psVec = psVectorExtend(psVec, 0, -20);
    173     if (psVec == NULL) {
    174         fprintf(stderr,"ERROR: Return is NULL\n");
    175         return 30;
    176     }
    177     if (psVec->nalloc != 15) { // no growth
    178         fprintf(stderr,"Vector size = %ld\n", psVec->nalloc);
    179         return 31;
    180     }
    181     if (psVec->n != 0) {
    182         fprintf(stderr,"Vector population = %ld\n", psVec->n);
    183         return 32;
    184     }
    185 
    186     psFree(psVec);
    187 
    188     return 0;
    189 }
    190 
    191180psS32 testVectorInit(void)
    192181{
Note: See TracChangeset for help on using the changeset viewer.