IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18333


Ignore:
Timestamp:
Jun 26, 2008, 12:30:34 PM (18 years ago)
Author:
Paul Price
Message:

Adding additional test case.

File:
1 edited

Legend:

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

    r18332 r18333  
    4242}
    4343
     44// Test that results of psVectorSelectInPlace match what you'd get from psVectorSort
     45// 2 tests
     46static void testSelectInPlace(int size,        // Size of vector
     47                       int numNonzero   // Number of non-zero values
     48                       )
     49{
     50    psMemId id = psMemGetId();
     51
     52    psVector *vector = psVectorAlloc(size, PS_TYPE_F32);
     53    psVectorInit(vector, 0.0);
     54    psRandom *rng = psRandomAlloc(PS_RANDOM_TAUS, 12345);
     55    for (long i = 0; i < numNonzero; i++) {
     56        long index = psRandomUniform(rng) * size;
     57        vector->data.F32[index] = psRandomUniform(rng);
     58    }
     59    psFree(rng);
     60
     61    psVector *sorted = psVectorSort(NULL, vector); // Sorted vector
     62    bool match = true;              // Everything matches
     63    for (long i = 0; i < size && match; i++) {
     64        psVectorSelectInPlace(vector, i);
     65        if (vector->data.F32[i] != sorted->data.F32[i]) {
     66            match = false;
     67            diag("Rank %ld doesn't match: %f vs %f", i, vector->data.F32[i], sorted->data.F32[i]);
     68        }
     69    }
     70    psFree(sorted);
     71    psFree(vector);
     72
     73    ok(match, "All selections in-place match, size=%d, number non-zero=%d.", size, numNonzero);
     74    ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks");
     75}
     76
    4477
    4578int main(int argc, char *argv[])
    4679{
    47     plan_tests(5 * 2);
     80    plan_tests(6 * 2 + 6 * 2);
    4881
    4982    testSelect(100, 0);
     83    testSelect(100, 1);
    5084    testSelect(100, 10);
    5185    testSelect(100, 100);
     
    5387    testSelect(137, 137);
    5488
     89    testSelectInPlace(100, 0);
     90    testSelectInPlace(100, 1);
     91    testSelectInPlace(100, 10);
     92    testSelectInPlace(100, 100);
     93    testSelectInPlace(137, 13);
     94    testSelectInPlace(137, 137);
     95
    5596    return PS_EXIT_SUCCESS;
    5697}
Note: See TracChangeset for help on using the changeset viewer.