opengl_learn

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

vec3f_normal.test.c (1585B)


      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 	struct ogl_vec3f correct;
     16 };
     17 
     18 static int fail = 0;
     19 
     20 static void
     21 _test(struct _test_values values) {
     22 	printf("[TEST]");
     23 
     24 	struct ogl_vec3f output;
     25 	int status = ogl_vec3f_normal(values.a, &output);
     26 	int pass_status = (status >= 0);
     27 	int pass_output = ogl_vec3f_isapproxequal(output, values.correct);
     28 	if (pass_status && pass_output) {
     29 		printf("[ OK ] (%s)" "\n", values.desc);
     30 	}
     31 	else {
     32 		fail = 1;
     33 
     34 		printf("[FAIL] (%s)" "\n", values.desc);
     35 
     36 		if (!pass_status) {
     37 			printf("\t" "status FAIL: %i" "\n", status);
     38 		}
     39 		else {
     40 			printf("\t" "status OK: %i" "\n", status);
     41 		}
     42 
     43 		if (!pass_output) {
     44 			printf("\t" "output FAIL:" "\n");
     45 
     46 			printf("\t\t" "|| ");
     47 			ogl_vec3f_print(values.a);
     48 			printf(" ||" "\n");
     49 
     50 			printf("\t\t" "was" "\n");
     51 
     52 			printf("\t\t");
     53 			ogl_vec3f_print(output);
     54 			printf("\n");
     55 
     56 			printf("\t\t" "should be" "\n");
     57 
     58 			printf("\t\t");
     59 			ogl_vec3f_print(values.correct);
     60 			printf("\n");
     61 		}
     62 		else {
     63 			printf("\t" "output OK" "\n");
     64 		}
     65 	}
     66 }
     67 
     68 int
     69 main() {
     70 	struct _test_values testvalues[] = {
     71 		{ .desc="vec3f normal() test 1", .a={.x=1.0f, .y=2.0f, .z=3.0f}, .correct={.x=0.267261f, .y=0.534522f, .z=0.801784f}},
     72 	};
     73 	size_t testvalues_length = sizeof(testvalues) / sizeof(*testvalues);
     74 	for (size_t i=0; i<testvalues_length; i++) {
     75 		_test(testvalues[i]);
     76 	}
     77 
     78 	if (fail) {
     79 		return -1;
     80 	}
     81 
     82 	return 0;
     83 }
     84