mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 01:00:46 +00:00
re-organise test structure
This commit is contained in:
36
test/src/test_common.c
Normal file
36
test/src/test_common.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
void
|
||||
test_rand_mat4(mat4 dest) {
|
||||
int i, j;
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
dest[i][j] = drand48();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_assert_mat4_eq(mat4 m1, mat4 m2) {
|
||||
int i, j, k;
|
||||
|
||||
#define m 4
|
||||
#define n 4
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
assert_true(fabsf(m1[i][j] - m2[i][j]) <= FLT_EPSILON);
|
||||
}
|
||||
}
|
||||
#undef m
|
||||
#undef n
|
||||
}
|
||||
|
@@ -14,27 +14,18 @@
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <cglm.h>
|
||||
#include <cglm-call.h>
|
||||
|
||||
#define precision 0.00001f
|
||||
|
||||
static
|
||||
void
|
||||
test_rand_mat4(mat4 dest);
|
||||
|
||||
static
|
||||
void
|
||||
test_rand_mat4(mat4 dest) {
|
||||
int i, j;
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
dest[i][j] = drand48();
|
||||
}
|
||||
}
|
||||
}
|
||||
test_assert_mat4_eq(mat4 m1, mat4 m2);
|
||||
|
||||
#endif /* test_common_h */
|
||||
|
19
test/src/test_main.c
Normal file
19
test/src/test_main.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test_tests.h"
|
||||
|
||||
int
|
||||
main(int argc, const char * argv[]) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
/* mat4 */
|
||||
cmocka_unit_test(test_mat4),
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests,
|
||||
NULL,
|
||||
NULL);
|
||||
}
|
@@ -5,18 +5,13 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define m 4
|
||||
#define n 4
|
||||
|
||||
void
|
||||
test_mat4_mul(void **state) {
|
||||
test_mat4(void **state) {
|
||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m3;
|
||||
@@ -48,30 +43,9 @@ test_mat4_mul(void **state) {
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
assert_true(fabsf(m3[i][j] - m4[i][j]) <= FLT_EPSILON);
|
||||
}
|
||||
}
|
||||
test_assert_mat4_eq(m3, m4);
|
||||
|
||||
/* test pre compiled */
|
||||
glmc_mat4_mul(m1, m2, m3);
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
assert_true(fabsf(m3[i][j] - m4[i][j]) <= FLT_EPSILON);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, const char * argv[]) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
cmocka_unit_test(test_mat4_mul)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests,
|
||||
NULL,
|
||||
NULL);
|
||||
test_assert_mat4_eq(m3, m4);
|
||||
}
|
||||
|
12
test/src/test_tests.h
Normal file
12
test/src/test_tests.h
Normal file
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#ifndef test_tests_h
|
||||
#define test_tests_h
|
||||
|
||||
/* mat4 */
|
||||
void test_mat4(void **state);
|
||||
|
||||
#endif /* test_tests_h */
|
Reference in New Issue
Block a user