diff --git a/test/src/test_affine_mat.h b/test/src/test_affine_mat.h new file mode 100644 index 0000000..545839b --- /dev/null +++ b/test/src/test_affine_mat.h @@ -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 +} diff --git a/test/src/tests.c b/test/src/tests.c index 857dea1..ee7c488 100644 --- a/test/src/tests.c +++ b/test/src/tests.c @@ -20,6 +20,7 @@ #include "test_project.h" #include "test_plane.h" #include "test_affine.h" +#include "test_affine_mat.h" #undef GLM #undef GLM_PREFIX @@ -38,6 +39,7 @@ #include "test_project.h" #include "test_plane.h" #include "test_affine.h" +#include "test_affine_mat.h" #undef GLM #undef GLM_PREFIX diff --git a/test/tests.h b/test/tests.h index 37475a8..e4933e9 100644 --- a/test/tests.h +++ b/test/tests.h @@ -16,6 +16,15 @@ * 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 */ TEST_DECLARE(glm_translate) TEST_DECLARE(glm_translate_to) @@ -579,6 +588,15 @@ TEST_DECLARE(vec4s_zero_init) /*****************************************************************************/ 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 */ TEST_ENTRY(glm_translate) TEST_ENTRY(glm_translate_to)