defocus-modules/tests/tests.c
2023-05-08 13:28:53 +02:00

68 lines
1.8 KiB
C

#include "munit.h"
#include <defocus/defocus.h>
static MunitResult test_transforms_identity(const MunitParameter params[], void *user_data)
{
/* Check that the identity matrix does what it's supposed to do. */
/* clang-format off */
df_m4 identity = {
{1.f, 0.f, 0.f, 0.f,
0.f, 1.f, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f}
};
/* clang-format on */
df_v3 v = {1.f, 2.f, 3.f};
df_v3 identity_transform = df_transform_v3(identity, v);
munit_assert_double_equal(v.x, identity_transform.x, 6);
munit_assert_double_equal(v.y, identity_transform.y, 6);
munit_assert_double_equal(v.z, identity_transform.z, 6);
return MUNIT_OK;
}
static MunitResult test_transforms_translation(const MunitParameter params[], void *user_data)
{
/* Check that the identity matrix does what it's supposed to do. */
/* clang-format off */
df_m4 translate = {
{1.f, 0.f, 0.f, 1.f,
0.f, 1.f, 0.f, -1.f,
0.f, 0.f, 1.f, .5f,
0.f, 0.f, 0.f, 1.f}
};
/* clang-format on */
df_v3 v = {1.f, 2.f, 3.f};
df_v3 tv = df_transform_v3(translate, v);
munit_assert_double_equal(tv.x, v.x + 1.f, 6);
munit_assert_double_equal(tv.y, v.y - 1.f, 6);
munit_assert_double_equal(tv.z, v.z + .5f, 6);
return MUNIT_OK;
}
static MunitTest _tests[] = {
{(char *)"/math/transforms/identity", test_transforms_identity, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{(char *)"/math/transforms/translation", test_transforms_translation, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL},
{NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL}};
static MunitSuite _test_suite = {
"",
_tests,
NULL,
1,
MUNIT_SUITE_OPTION_NONE,
};
int main(int argc, char **argv)
{
munit_suite_main(&_test_suite, NULL, argc, argv);
return 0;
}