Skip to content

Instantly share code, notes, and snippets.

@domitry
Created April 20, 2016 08:35
Show Gist options
  • Save domitry/b899b8c00cc5dd8c18eed854b617fa1e to your computer and use it in GitHub Desktop.
Save domitry/b899b8c00cc5dd8c18eed854b617fa1e to your computer and use it in GitHub Desktop.
gcc testMathTool.c MathTool.c -lm -o test.out
./test.out
rm ./test.out
#include "MathTool.h"
#define Test(a_) printf("Test name: %s\n", a_);if(1)
#define init(v, x_, y_, z_) v.x=x_;v.y=y_;v.z=z_;
void printResult(int boolean){
if(boolean)
printf("\033[32mTest passed.\n\033[0;m");
else
printf("\033[1;31mTest failed.\n\033[0;m");
}
void checkVec3(Vec3d* a, Vec3d* b){
printResult(isEqualVec3andVec3(a, b));
}
void checkD(double a, double b){
printResult((a-b)*(a-b)<EPS);
}
int main(){
Vec3d a, b, c, res;
Test("clearVec3"){
init(a, 1.,2.,3.);
init(res, 0., 0., 0.);
clearVec3(&a);
checkVec3(&a, &res);
}
Test("sumVec3andVec3"){
init(a, 1., 2., 3.);
init(b, 1., 2., 3.);
init(res, 2., 4., 6.);
sumVec3andVec3(&a, &b, &c);
checkVec3(&c, &res);
}
Test("subVec3andVec3"){
init(a, 2., 3., 4.);
init(b, 1., 2., 3.);
init(res, 1., 1., 1.);
subVec3andVec3(&a, &b, &c);
checkVec3(&c, &res);
}
Test("scalingVec3"){
init(a, 1., 2., 3.);
init(res, 2., 4., 6.);
scalingVec3(2., &a, &c);
checkVec3(&c, &res);
}
Test("dotVec3andVec3"){
init(a, 1., 0., 0.);
init(b, 0., 1., 0.);
checkD(dotVec3andVec3(&a, &b), 0.);
}
Test("crossVec3andVec3"){
init(a, 1., 0., 0.);
init(b, 0., 1., 0.);
init(res, 0., 0., 1.);
crossVec3andVec3(&a, &b, &c);
checkVec3(&c, &res);
}
Test("absVec3"){
init(a, 1., 1., 0.);
checkD(absVec3(&a), sqrt(2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment