opengl_learn

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

mat4f_multiply.test.c (1685B)


      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_mat4f a;
     13 	struct ogl_mat4f b;
     14 	struct ogl_mat4f 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_mat4f result;
     24 	ogl_mat4f_multiply(values.a, values.b, &result);
     25 
     26 	int pass = ogl_mat4f_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 		ogl_mat4f_print(values.a, "\t", NULL);
     36 
     37 		printf("\t" "*" "\n");
     38 
     39 		ogl_mat4f_print(values.b, "\t", NULL);
     40 
     41 		printf("\t" "was" "\n");
     42 
     43 		ogl_mat4f_print(result, "\t", NULL);
     44 
     45 		printf("\t" "should be" "\n");
     46 
     47 		ogl_mat4f_print(values.correct, "\t", NULL);
     48 	}
     49 }
     50 
     51 int
     52 main() {
     53 	struct _test_values testvalues[] = {
     54 		{
     55 			.desc="mat4f multiply() test 1",
     56 			.a={.values={
     57 				  0.0f,   1.0f,   2.0f,   3.0f,
     58 				  4.0f,   5.0f,   6.0f,   7.0f,
     59 				  8.0f,   9.0f,  10.0f,  11.0f,
     60 				 12.0f,  13.0f,  14.0f,  15.0f,
     61 			}},
     62 			.b={.values={
     63 				  0.0f,   1.0f,   2.0f,   3.0f,
     64 				  4.0f,   5.0f,   6.0f,   7.0f,
     65 				  8.0f,   9.0f,  10.0f,  11.0f,
     66 				 12.0f,  13.0f,  14.0f,  15.0f,
     67 			}},
     68 			.correct={.values={
     69 				 56.0f,  62.0f,  68.0f,  74.0f,
     70 				152.0f, 174.0f, 196.0f, 218.0f,
     71 				248.0f, 286.0f, 324.0f, 362.0f,
     72 				344.0f, 398.0f, 452.0f, 506.0f,
     73 			}},
     74 		},
     75 	};
     76 	size_t testvalues_length = sizeof(testvalues) / sizeof(*testvalues);
     77 	for (size_t i=0; i<testvalues_length; i++) {
     78 		_test(testvalues[i]);
     79 	}
     80 
     81 	if (fail) {
     82 		return -1;
     83 	}
     84 
     85 	return 0;
     86 }
     87