mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
test: test mat4_mul
This commit is contained in:
16
makefile.am
16
makefile.am
@@ -18,6 +18,20 @@ AM_CFLAGS = -Wall \
|
|||||||
lib_LTLIBRARIES = libcglm.la
|
lib_LTLIBRARIES = libcglm.la
|
||||||
libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0
|
libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0
|
||||||
|
|
||||||
|
checkLDFLAGS = -L./.libs \
|
||||||
|
-L./test/lib/cmocka/build/src \
|
||||||
|
-lcmocka \
|
||||||
|
-lm \
|
||||||
|
-lcglm
|
||||||
|
checkCFLAGS = -I./test/lib/cmocka/include \
|
||||||
|
-I./include
|
||||||
|
|
||||||
|
check_PROGRAMS = test/test_mat4
|
||||||
|
TESTS = $(check_PROGRAMS)
|
||||||
|
|
||||||
|
test_test_mat4_LDFLAGS = $(checkLDFLAGS)
|
||||||
|
test_test_mat4_CFLAGS = $(checkCFLAGS)
|
||||||
|
|
||||||
nobase_include_HEADERS = include/cglm.h \
|
nobase_include_HEADERS = include/cglm.h \
|
||||||
include/cglm-call.h \
|
include/cglm-call.h \
|
||||||
include/cglm-cam.h \
|
include/cglm-cam.h \
|
||||||
@@ -57,3 +71,5 @@ libcglm_la_SOURCES=\
|
|||||||
src/cglm-vec.c \
|
src/cglm-vec.c \
|
||||||
src/cglm-mat3.c \
|
src/cglm-mat3.c \
|
||||||
src/cglm-mat.c
|
src/cglm-mat.c
|
||||||
|
|
||||||
|
test_test_mat4_SOURCES=test/src/test_mat4.c
|
||||||
|
40
test/src/test_common.h
Normal file
40
test/src/test_common.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* Full license can be found in the LICENSE file
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef test_common_h
|
||||||
|
#define test_common_h
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <setjmp.h>
|
||||||
|
#include <cmocka.h>
|
||||||
|
#include <time.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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* test_common_h */
|
77
test/src/test_mat4.c
Normal file
77
test/src/test_mat4.c
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c), Recep Aslantas.
|
||||||
|
*
|
||||||
|
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||||
|
* 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) {
|
||||||
|
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||||
|
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||||
|
mat4 m3;
|
||||||
|
mat4 m4 = GLM_MAT4_ZERO_INIT;
|
||||||
|
int i, j, k;
|
||||||
|
|
||||||
|
/* test identity matrix multiplication */
|
||||||
|
glm_mat4_mul(m1, m2, m3);
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
for (j = 0; j < n; j++) {
|
||||||
|
if (i == j)
|
||||||
|
assert_true(m3[i][j] == 1.0f);
|
||||||
|
else
|
||||||
|
assert_true(m3[i][j] == 0.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* test random matrices */
|
||||||
|
/* random matrices */
|
||||||
|
test_rand_mat4(m1);
|
||||||
|
test_rand_mat4(m2);
|
||||||
|
|
||||||
|
glm_mat4_mul(m1, m2, m3);
|
||||||
|
for (i = 0; i < m; i++) {
|
||||||
|
for (j = 0; j < n; j++) {
|
||||||
|
for (k = 0; k < m; k++)
|
||||||
|
/* column-major */
|
||||||
|
m4[i][j] += m1[k][j] * m2[i][k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 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);
|
||||||
|
}
|
Reference in New Issue
Block a user