tests: add some tests for affine matrices

This commit is contained in:
Recep Aslantas
2020-02-22 10:54:47 +03:00
parent 0c8dc070d5
commit 7b0f62f1eb
3 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#include "test_common.h"
TEST_IMPL(GLM_PREFIX, mul) {
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_rand_mat4(m1);
test_rand_mat4(m2);
GLM(mul)(m1, m2, m3);
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++)
/* column-major */
m4[i][j] += m1[k][j] * m2[i][k];
}
}
ASSERTIFY(test_assert_mat4_eq(m3, m4))
/* test pre compiled */
GLM(mul)(m1, m2, m3);
ASSERTIFY(test_assert_mat4_eq(m3, m4))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, mul_rot) {
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
mat4 m3;
mat4 m4 = GLM_MAT4_ZERO_INIT;
int i, j, k;
glm_rotate(m1, drand48(), (vec3){drand48(), drand48(), drand48()});
glm_rotate(m2, drand48(), (vec3){drand48(), drand48(), drand48()});
GLM(mul)(m1, m2, m3);
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++)
/* column-major */
m4[i][j] += m1[k][j] * m2[i][k];
}
}
ASSERTIFY(test_assert_mat4_eq(m3, m4))
/* test pre compiled */
GLM(mul)(m1, m2, m3);
ASSERTIFY(test_assert_mat4_eq(m3, m4))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, inv_tr) {
mat4 m1, m2, m3;
int i;
for (i = 0; i < 10000; i++) {
test_rand_mat4(m1);
glm_mat4_copy(m1, m2);
/* test inverse precise */
GLM(inv_tr)(m1);
GLM(inv_tr)(m1);
ASSERTIFY(test_assert_mat4_eq(m1, m2))
/* test inverse precise */
GLM(mat4_inv)(m1, m2);
GLM(inv_tr)(m2);
ASSERTIFY(test_assert_mat4_eq(m1, m2))
}
TEST_SUCCESS
}

View File

@@ -20,6 +20,7 @@
#include "test_project.h" #include "test_project.h"
#include "test_plane.h" #include "test_plane.h"
#include "test_affine.h" #include "test_affine.h"
#include "test_affine_mat.h"
#undef GLM #undef GLM
#undef GLM_PREFIX #undef GLM_PREFIX
@@ -38,6 +39,7 @@
#include "test_project.h" #include "test_project.h"
#include "test_plane.h" #include "test_plane.h"
#include "test_affine.h" #include "test_affine.h"
#include "test_affine_mat.h"
#undef GLM #undef GLM
#undef GLM_PREFIX #undef GLM_PREFIX

View File

@@ -16,6 +16,15 @@
* 2. use TEST_ENTRY() to add test to list * 2. use TEST_ENTRY() to add test to list
*/ */
/* affine mat */
TEST_DECLARE(glm_mul)
TEST_DECLARE(glm_mul)
TEST_DECLARE(glm_inv_tr)
TEST_DECLARE(glmc_mul)
TEST_DECLARE(glmc_mul_rot)
TEST_DECLARE(glmc_inv_tr)
/* affine */ /* affine */
TEST_DECLARE(glm_translate) TEST_DECLARE(glm_translate)
TEST_DECLARE(glm_translate_to) TEST_DECLARE(glm_translate_to)
@@ -579,6 +588,15 @@ TEST_DECLARE(vec4s_zero_init)
/*****************************************************************************/ /*****************************************************************************/
TEST_LIST { TEST_LIST {
/* affine mat */
TEST_ENTRY(glm_mul)
TEST_ENTRY(glm_mul)
TEST_ENTRY(glm_inv_tr)
TEST_ENTRY(glmc_mul)
TEST_ENTRY(glmc_mul_rot)
TEST_ENTRY(glmc_inv_tr)
/* affine */ /* affine */
TEST_ENTRY(glm_translate) TEST_ENTRY(glm_translate)
TEST_ENTRY(glm_translate_to) TEST_ENTRY(glm_translate_to)