IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 7786


Ignore:
Timestamp:
Jul 1, 2006, 12:10:49 PM (20 years ago)
Author:
jhoblitt
Message:

add psVectorCreate() tests

File:
1 edited

Legend:

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

    r7785 r7786  
    55int main (void)
    66{
    7     plan_tests(62);
     7    plan_tests(122);
    88
    99    diag("psVectorAlloc() tests");
     
    4444        psFree(vecBogus);
    4545    }
     46
    4647
    4748    diag("psVectorRealloc() tests");
     
    120121    }
    121122
     123
    122124    diag("psVectorExtend() tests");
    123125
     
    174176    }
    175177
     178
    176179    diag("psVectorInit() tests");
    177180
     
    251254    }
    252255
     256
     257    diag("psVectorCreate() tests");
     258
     259    {
     260        psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S32);
     261        for (int i = 0; i < 10; i++) {
     262            ok(test->data.S32[i] == i, "Vector data matches. i = %d, data=%d",
     263               i, test->data.S32[i]);
     264        }
     265        psFree(test);
     266    }
     267
     268    {
     269        psVector *input = psVectorAlloc(5, PS_TYPE_F32);
     270        psVector *test = psVectorCreate(input, 0.0, 5.0, 0.5, PS_TYPE_F32);
     271
     272        for (int i = 0; i < 10; i++) {
     273            ok(test->data.F32[i] == i * 0.5,
     274               "Vector data matches. i = %d, data=%f", i, test->data.F32[i]);
     275        }
     276
     277        psFree(input);
     278    }
     279
     280    //  Test PS_TYPE_F64
     281    //       PS_TYPE_S64
     282    {
     283        psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S64);
     284        for (int i = 0; i < 10; i++)
     285        {
     286            ok(test->data.S64[i] == i,
     287               "Vector data does not match. i = %d, data=%ld",
     288               i, (long)test->data.S64[i]);
     289        }
     290        psFree(test);
     291    }
     292
     293    {
     294        psVector *input = psVectorAlloc(5, PS_TYPE_F64);
     295        psVector *test = psVectorCreate(input, 0.0, 5.0, 0.5, PS_TYPE_F64);
     296
     297        for (int i = 0; i < 10; i++)
     298        {
     299            ok(test->data.F64[i] == i * 0.5,
     300               "Vector data does not match. i = %d, data=%f",
     301               i, test->data.F64[i]);
     302        }
     303        psFree(input);
     304    }
     305
     306    //  Test PS_TYPE_U16
     307    //       PS_TYPE_S16
     308    {
     309        psVector *test = psVectorCreate(NULL, 0.0, 10.0, 1.0, PS_TYPE_S16);
     310        for (int i = 0; i < 10; i++)
     311        {
     312            ok(test->data.S16[i] == i, "Vector data matches. i = %d, data=%d",
     313               i, test->data.S16[i]);
     314        }
     315        psFree(test);
     316    }
     317
     318    {
     319        psVector *input = psVectorAlloc(5, PS_TYPE_U16);
     320        psVector *test = psVectorCreate(input, 0.0, 20.0, 2.0, PS_TYPE_U16);
     321
     322        for (int i = 0; i < 10; i++)
     323        {
     324            ok(test->data.U16[i] == i * 2.0,
     325               "Vector data matches. i = %d, data=%d", i, test->data.U16[i]);
     326        }
     327        psFree(input);
     328    }
     329
    253330    return exit_status();
    254331}
    255332
    256333# if 0
    257 
    258 psS32 testVectorCreate(void)
    259 {
    260     psVector *test = NULL;
    261     psVector *test2 = NULL;
    262     psVector *input = NULL;
    263     psVector *input2 = psVectorAlloc(5, PS_TYPE_F32);
    264 
    265     test = psVectorCreate(input, 0.0, 10.0, 1.0, PS_TYPE_S32);
    266     test2 = psVectorCreate(input2, 0.0, 5.0, 0.5, PS_TYPE_F32);
    267 
    268     for (int i = 0; i < 10; i++) {
    269         if (test->data.S32[i] != i) {
    270             fprintf(stderr, "Vector data does not match. i = %d, data=%d\n",
    271                     i, test->data.S32[i]);
    272             return 1;
    273         }
    274         if (test2->data.F32[i] != i*0.5) {
    275             fprintf(stderr, "Vector data does not match. i = %d, data=%f\n",
    276                     i, test->data.F32[i]);
    277             return 1;
    278         }
    279     }
    280     psFree(test);
    281     psFree(test2);
    282     return 0;
    283 }
    284 psS32 testVectorCreateA(void)
    285 {
    286     //
    287     //  Test PS_TYPE_F64
    288     //       PS_TYPE_S64
    289     //
    290     psVector *test = NULL;
    291     psVector *test2 = NULL;
    292     psVector *input = NULL;
    293     psVector *input2 = psVectorAlloc(5, PS_TYPE_F64);
    294 
    295     test = psVectorCreate(input, 0.0, 10.0, 1.0, PS_TYPE_S64);
    296     test2 = psVectorCreate(input2, 0.0, 5.0, 0.5, PS_TYPE_F64);
    297 
    298     for (int i = 0; i < 10; i++) {
    299         if (test->data.S64[i] != i) {
    300             fprintf(stderr, "Vector data does not match. i = %d, data=%ld\n",
    301                     i, (long)test->data.S64[i]);
    302             return 1;
    303         }
    304         if (test2->data.F64[i] != i*0.5) {
    305             fprintf(stderr, "Vector data does not match. i = %d, data=%f\n",
    306                     i, test->data.F64[i]);
    307             return 1;
    308         }
    309     }
    310     psFree(test);
    311     psFree(test2);
    312     return 0;
    313 }
    314 psS32 testVectorCreateB(void)
    315 {
    316     //
    317     //  Test PS_TYPE_U16
    318     //       PS_TYPE_S16
    319     //
    320     psVector *test = NULL;
    321     psVector *test2 = NULL;
    322     psVector *input = NULL;
    323     psVector *input2 = psVectorAlloc(5, PS_TYPE_U16);
    324 
    325     test = psVectorCreate(input, 0.0, 10.0, 1.0, PS_TYPE_S16);
    326     test2 = psVectorCreate(input2, 0.0, 20.0, 2.0, PS_TYPE_U16);
    327 
    328     for (int i = 0; i < 10; i++) {
    329         if (test->data.S16[i] != i) {
    330             fprintf(stderr, "Vector data does not match. i = %d, data=%d\n",
    331                     i, test->data.S16[i]);
    332             return 1;
    333         }
    334         if (test2->data.U16[i] != i*2.0) {
    335             fprintf(stderr, "Vector data does not match. i = %d, data=%d\n",
    336                     i, test->data.U16[i]);
    337             return 1;
    338         }
    339     }
    340     psFree(test);
    341     psFree(test2);
    342     return 0;
    343 }
    344334psS32 testVectorGetSet(void)
    345335{
Note: See TracChangeset for help on using the changeset viewer.