mirror of
https://github.com/recp/cglm.git
synced 2025-10-04 09:08:53 +00:00
test: add missing mat2x3 tests
Signed-off-by: Vincent Davis Jr <vince@underview.tech>
This commit is contained in:
@@ -31,6 +31,16 @@ test_rand_mat3(mat3 dest) {
|
||||
glm_mat4_pick3(m4, dest);
|
||||
}
|
||||
|
||||
void
|
||||
test_rand_mat3x2(mat3x2 dest) {
|
||||
dest[0][0] = drand48();
|
||||
dest[0][1] = drand48();
|
||||
dest[1][0] = drand48();
|
||||
dest[1][1] = drand48();
|
||||
dest[2][0] = drand48();
|
||||
dest[2][1] = drand48();
|
||||
}
|
||||
|
||||
void
|
||||
test_rand_mat2(mat2 dest) {
|
||||
dest[0][0] = drand48();
|
||||
@@ -39,6 +49,16 @@ test_rand_mat2(mat2 dest) {
|
||||
dest[1][1] = drand48();
|
||||
}
|
||||
|
||||
void
|
||||
test_rand_mat2x3(mat2x3 dest) {
|
||||
dest[0][0] = drand48();
|
||||
dest[0][1] = drand48();
|
||||
dest[0][2] = drand48();
|
||||
dest[1][0] = drand48();
|
||||
dest[1][1] = drand48();
|
||||
dest[1][2] = drand48();
|
||||
}
|
||||
|
||||
void
|
||||
test_rand_vec3(vec3 dest) {
|
||||
dest[0] = drand48();
|
||||
@@ -187,6 +207,19 @@ test_assert_mat2x3_eq_zero(mat2x3 m2x3) {
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat2x3_eq(mat2x3 m1, mat2x3 m2) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat2x4_eq_zero(mat2x4 m2x4) {
|
||||
int i, j;
|
||||
@@ -269,6 +302,19 @@ test_assert_mat3x2_eq_zero(mat3x2 m3x2) {
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3x2_eq(mat3x2 m1, mat3x2 m2) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3x4_eq_zero(mat3x4 m3x4) {
|
||||
int i, j;
|
||||
|
@@ -20,9 +20,15 @@ test_rand_mat4(mat4 dest);
|
||||
void
|
||||
test_rand_mat3(mat3 dest);
|
||||
|
||||
void
|
||||
test_rand_mat3x2(mat3x2 dest);
|
||||
|
||||
void
|
||||
test_rand_mat2(mat2 dest);
|
||||
|
||||
void
|
||||
test_rand_mat2x3(mat2x3 dest);
|
||||
|
||||
test_status_t
|
||||
test_assert_eqf(float a, float b);
|
||||
|
||||
@@ -62,6 +68,9 @@ test_assert_mat2_eq_zero(mat2 m2);
|
||||
test_status_t
|
||||
test_assert_mat2x3_eq_zero(mat2x3 m2x3);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat2x3_eq(mat2x3 m1, mat2x3 m2);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat2x4_eq_zero(mat2x4 m2x4);
|
||||
|
||||
@@ -83,6 +92,9 @@ test_assert_mat3_eq_zero(mat3 m3);
|
||||
test_status_t
|
||||
test_assert_mat3x2_eq_zero(mat3x2 m3x2);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3x2_eq(mat3x2 m1, mat3x2 m2);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3x4_eq_zero(mat3x4 m3x4);
|
||||
|
||||
|
@@ -7,6 +7,9 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define A_MATRIX2X3 {{1,2,3},{5,6,7}}
|
||||
#define A_MATRIX2X3_TRANSPOSE {{1,5}, {2,6}, {3,7}}
|
||||
|
||||
#ifndef CGLM_TEST_MAT2X3_ONCE
|
||||
#define CGLM_TEST_MAT2X3_ONCE
|
||||
|
||||
@@ -24,6 +27,31 @@ TEST_IMPL(MACRO_GLM_MAT2X3_ZERO) {
|
||||
|
||||
#endif /* CGLM_TEST_MAT2X3_ONCE */
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_copy) {
|
||||
mat2x3 m1 = A_MATRIX2X3;
|
||||
mat2x3 m2 = GLM_MAT2X3_ZERO_INIT;
|
||||
|
||||
GLM(mat2x3_copy)(m1, m2);
|
||||
|
||||
test_assert_mat2x3_eq(m1, m2);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_zero) {
|
||||
mat2x3 m1 = GLM_MAT2X3_ZERO_INIT;
|
||||
mat2x3 m2 = GLM_MAT2X3_ZERO_INIT;
|
||||
mat2x3 m3;
|
||||
|
||||
GLM(mat2x3_zero)(m3);
|
||||
|
||||
ASSERTIFY(test_assert_mat2x3_eq_zero(m1))
|
||||
ASSERTIFY(test_assert_mat2x3_eq_zero(m2))
|
||||
ASSERTIFY(test_assert_mat2x3_eq_zero(m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_make) {
|
||||
float src[18] = {
|
||||
0.5f, 1.7f, 10.3f, 4.2f, 8.9f, 1.1f,
|
||||
@@ -50,3 +78,79 @@ TEST_IMPL(GLM_PREFIX, mat2x3_make) {
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_mul) {
|
||||
mat2x3 m1 = GLM_MAT2X3_ZERO_INIT;
|
||||
mat3x2 m2 = GLM_MAT3X2_ZERO_INIT;
|
||||
|
||||
mat2 m3 = GLM_MAT2_ZERO_INIT;
|
||||
mat2 m4 = GLM_MAT2_ZERO_INIT;
|
||||
|
||||
int i, j, k;
|
||||
|
||||
/* test random matrices */
|
||||
/* random matrices */
|
||||
test_rand_mat2x3(m1);
|
||||
test_rand_mat3x2(m2);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (k = 0; k < 3; k++) {
|
||||
m4[i][j] += m1[i][k] * m2[k][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GLM(mat2x3_mul)(m1, m2, m3);
|
||||
ASSERTIFY(test_assert_mat2_eq(m3, m4))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_mulv) {
|
||||
mat2x3 mat = A_MATRIX2X3;
|
||||
vec3 v = {11.0f, 21.0f, 31.0f};
|
||||
|
||||
int i;
|
||||
vec2 dest;
|
||||
float res = 0.0;
|
||||
|
||||
GLM(mat2x3_mulv)(mat, v, dest);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
res = mat[i][0] * v[0] + mat[i][1] * v[1] + mat[i][2] * v[2];
|
||||
ASSERT(test_eq(dest[i], res))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_transpose) {
|
||||
mat2x3 m1 = A_MATRIX2X3;
|
||||
|
||||
mat3x2 m2;
|
||||
mat3x2 m3 = A_MATRIX2X3_TRANSPOSE;
|
||||
GLM(mat2x3_transpose)(m1, m2);
|
||||
|
||||
ASSERTIFY(test_assert_mat3x2_eq(m2, m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat2x3_scale) {
|
||||
mat2x3 m1 = A_MATRIX2X3;
|
||||
mat2x3 m2 = A_MATRIX2X3;
|
||||
int i, j, scale;
|
||||
|
||||
scale = rand() % 100;
|
||||
|
||||
GLM(mat2x3_scale)(m1, (float) scale);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(test_eq(m1[i][j], m2[i][j] * scale))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
24
test/tests.h
24
test/tests.h
@@ -254,9 +254,21 @@ TEST_DECLARE(glmc_mat2_make)
|
||||
|
||||
TEST_DECLARE(MACRO_GLM_MAT2X3_ZERO_INIT)
|
||||
TEST_DECLARE(MACRO_GLM_MAT2X3_ZERO)
|
||||
TEST_DECLARE(glm_mat2x3_copy)
|
||||
TEST_DECLARE(glm_mat2x3_zero)
|
||||
TEST_DECLARE(glm_mat2x3_make)
|
||||
TEST_DECLARE(glm_mat2x3_mul)
|
||||
TEST_DECLARE(glm_mat2x3_mulv)
|
||||
TEST_DECLARE(glm_mat2x3_transpose)
|
||||
TEST_DECLARE(glm_mat2x3_scale)
|
||||
|
||||
TEST_DECLARE(glmc_mat2x3_copy)
|
||||
TEST_DECLARE(glmc_mat2x3_zero)
|
||||
TEST_DECLARE(glmc_mat2x3_make)
|
||||
TEST_DECLARE(glmc_mat2x3_mul)
|
||||
TEST_DECLARE(glmc_mat2x3_mulv)
|
||||
TEST_DECLARE(glmc_mat2x3_transpose)
|
||||
TEST_DECLARE(glmc_mat2x3_scale)
|
||||
|
||||
TEST_DECLARE(MACRO_GLM_MAT2X4_ZERO_INIT)
|
||||
TEST_DECLARE(MACRO_GLM_MAT2X4_ZERO)
|
||||
@@ -1157,9 +1169,21 @@ TEST_LIST {
|
||||
|
||||
TEST_ENTRY(MACRO_GLM_MAT2X3_ZERO_INIT)
|
||||
TEST_ENTRY(MACRO_GLM_MAT2X3_ZERO)
|
||||
TEST_ENTRY(glm_mat2x3_copy)
|
||||
TEST_ENTRY(glm_mat2x3_zero)
|
||||
TEST_ENTRY(glm_mat2x3_make)
|
||||
TEST_ENTRY(glm_mat2x3_mul)
|
||||
TEST_ENTRY(glm_mat2x3_mulv)
|
||||
TEST_ENTRY(glm_mat2x3_transpose)
|
||||
TEST_ENTRY(glm_mat2x3_scale)
|
||||
|
||||
TEST_ENTRY(glmc_mat2x3_copy)
|
||||
TEST_ENTRY(glmc_mat2x3_zero)
|
||||
TEST_ENTRY(glmc_mat2x3_make)
|
||||
TEST_ENTRY(glmc_mat2x3_mul)
|
||||
TEST_ENTRY(glmc_mat2x3_mulv)
|
||||
TEST_ENTRY(glmc_mat2x3_transpose)
|
||||
TEST_ENTRY(glmc_mat2x3_scale)
|
||||
|
||||
TEST_ENTRY(MACRO_GLM_MAT2X4_ZERO_INIT)
|
||||
TEST_ENTRY(MACRO_GLM_MAT2X4_ZERO)
|
||||
|
Reference in New Issue
Block a user