From 21ec45b2af4d664b62477235ec290f3b262764be Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Thu, 22 Mar 2018 21:24:41 +0300 Subject: [PATCH] add tests for clamp --- makefile.am | 3 ++- test/src/test_clamp.c | 30 ++++++++++++++++++++++++++++++ test/src/test_main.c | 5 ++++- test/src/test_tests.h | 3 +++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 test/src/test_clamp.c diff --git a/makefile.am b/makefile.am index f6d1471..0767008 100644 --- a/makefile.am +++ b/makefile.am @@ -104,7 +104,8 @@ test_tests_SOURCES=\ test/src/test_common.c \ test/src/test_main.c \ test/src/test_mat4.c \ - test/src/test_cam.c + test/src/test_cam.c \ + test/src/test_clamp.c all-local: sh ./post-build.sh diff --git a/test/src/test_clamp.c b/test/src/test_clamp.c new file mode 100644 index 0000000..ee98958 --- /dev/null +++ b/test/src/test_clamp.c @@ -0,0 +1,30 @@ +/* + * 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" + +void +test_clamp(void **state) { + vec3 v3 = {15.07, 0.4, 17.3}; + vec4 v4 = {5.07, 2.3, 1.3, 1.4}; + + assert_true(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f); + assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f); + assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f); + + glm_vec_clamp(v3, 0.0, 1.0); + glm_vec4_clamp(v4, 1.5, 3.0); + + assert_true(v3[0] == 1.0f); + assert_true(v3[1] == 0.4f); + assert_true(v3[2] == 1.0f); + + assert_true(v4[0] == 3.0f); + assert_true(v4[1] == 2.3f); + assert_true(v4[2] == 1.5f); + assert_true(v4[3] == 1.5f); +} diff --git a/test/src/test_main.c b/test/src/test_main.c index 5d59cfd..4de5184 100644 --- a/test/src/test_main.c +++ b/test/src/test_main.c @@ -14,7 +14,10 @@ main(int argc, const char * argv[]) { /* camera */ cmocka_unit_test(test_camera_lookat), - cmocka_unit_test(test_camera_decomp) + cmocka_unit_test(test_camera_decomp), + + /* vector */ + cmocka_unit_test(test_clamp) }; return cmocka_run_group_tests(tests, NULL, NULL); diff --git a/test/src/test_tests.h b/test/src/test_tests.h index a4e5adb..fb9771e 100644 --- a/test/src/test_tests.h +++ b/test/src/test_tests.h @@ -16,4 +16,7 @@ test_camera_lookat(void **state); void test_camera_decomp(void **state); +void +test_clamp(void **state); + #endif /* test_tests_h */