opengl_learn

Step-by-step introduction to OpenGL
git clone https://0xdd.org/code/opengl_learn.git
Log | Files | Refs | README | LICENSE

vec3f_cross.test.c (1305B)


      1 /*
      2 2018 David DiPaola
      3 licensed under CC0 (public domain, see https://creativecommons.org/publicdomain/zero/1.0/)
      4 */
      5 
      6 #include <stdio.h>
      7 
      8 #include "ogl.h"
      9 
     10 struct _test_values {
     11 	const char * desc;
     12 	struct ogl_vec3f a;
     13 	struct ogl_vec3f b;
     14 	struct ogl_vec3f correct;
     15 };
     16 
     17 static int fail = 0;
     18 
     19 static void
     20 _test(struct _test_values values) {
     21 	printf("[TEST]");
     22 
     23 	struct ogl_vec3f result;
     24 	ogl_vec3f_cross(values.a, values.b, &result);
     25 
     26 	int pass = ogl_vec3f_isapproxequal(values.correct, result);
     27 	if (pass) {
     28 		printf("[ OK ] (%s)" "\n", values.desc);
     29 	}
     30 	else {
     31 		fail = 1;
     32 
     33 		printf("[FAIL] (%s)" "\n", values.desc);
     34 
     35 		printf("\t");
     36 		ogl_vec3f_print(values.a);
     37 		printf(" x ");
     38 		ogl_vec3f_print(values.b);
     39 		printf("\n");
     40 
     41 		printf("\t" "was" "\n");
     42 
     43 		printf("\t");
     44 		ogl_vec3f_print(result);
     45 		printf("\n");
     46 
     47 		printf("\t" "should be" "\n");
     48 
     49 		printf("\t");
     50 		ogl_vec3f_print(values.correct);
     51 		printf("\n");
     52 	}
     53 }
     54 
     55 int
     56 main() {
     57 	struct _test_values testvalues[] = {
     58 		{ .desc="vec3f cross() test 1", .a={.x=1.0f, .y=2.0f, .z=3.0f}, .b={.x=4.0f, .y=5.0f, .z=6.0f}, .correct={.x=-3.0f, .y=6.0f, .z=-3.0f} },
     59 	};
     60 	size_t testvalues_length = sizeof(testvalues) / sizeof(*testvalues);
     61 	for (size_t i=0; i<testvalues_length; i++) {
     62 		_test(testvalues[i]);
     63 	}
     64 
     65 	if (fail) {
     66 		return -1;
     67 	}
     68 
     69 	return 0;
     70 }
     71