opengl_learn

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

vec3f_magnitude.test.c (1176B)


      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 <GL/glew.h>
      9 
     10 #include "ogl.h"
     11 
     12 struct _test_values {
     13 	const char * desc;
     14 	struct ogl_vec3f a;
     15 	GLfloat correct;
     16 };
     17 
     18 static int fail = 0;
     19 
     20 static void
     21 _test(struct _test_values values) {
     22 	printf("[TEST]");
     23 
     24 	GLfloat result = ogl_vec3f_magnitude(values.a);
     25 	if (ogl_GLfloat_isapproxequal(result, values.correct)) {
     26 		printf("[ OK ] (%s)" "\n", values.desc);
     27 	}
     28 	else {
     29 		fail = 1;
     30 
     31 		printf("[FAIL] (%s)" "\n", values.desc);
     32 
     33 		printf("\t" "| ");
     34 		ogl_vec3f_print(values.a);
     35 		printf(" |" "\n");
     36 
     37 		printf("\t" "was" "\n");
     38 
     39 		printf("\t");
     40 		ogl_GLfloat_print(result);
     41 		printf("\n");
     42 
     43 		printf("\t" "should be" "\n");
     44 
     45 		printf("\t");
     46 		ogl_GLfloat_print(values.correct);
     47 		printf("\n");
     48 	}
     49 }
     50 
     51 int
     52 main() {
     53 	struct _test_values testvalues[] = {
     54 		{ .desc="vec3f magnitude() test 1", .a={.x=2.0f, .y=4.0f, .z=-2.0f}, .correct=4.89898f },
     55 	};
     56 	size_t testvalues_length = sizeof(testvalues) / sizeof(*testvalues);
     57 	for (size_t i=0; i<testvalues_length; i++) {
     58 		_test(testvalues[i]);
     59 	}
     60 
     61 	if (fail) {
     62 		return -1;
     63 	}
     64 
     65 	return 0;
     66 }
     67