vendredi 30 octobre 2015

Is there a more efficient way to use assert with arrays in C?

in one part of my program I need to use assert to test multiple arrays (5 sets total), and I was wondering if there's a more efficient way to do that besides what I am doing right now, which is basically just creating a new array every time. FYI I do have assert.h at the beginning of the program.

void UnitTest3D(void){
    double test1[3] = {0,0,0};
    double test2[3] = {5,0,0};
    assert(find3Ddistance(test1,test2) - 5) < 0.001);

    double test3[3] = {-2, -3, 3.4};
    double test4[3] = {-2, -3, -1.6};
    assert(find3Ddistance(test3,test4) - 5) < 0.001);

    double test5[3] = {-2, -3.2, -5};
    double test6[3] = {3, 1.8, 0};
    assert(find3Ddistance(test5,test6) - sqrt(75)) < 0.001);
    return;
    }

Aucun commentaire:

Enregistrer un commentaire