paysages: More unit testing

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@557 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-04-22 14:53:16 +00:00 committed by ThunderK
parent 0e0b39f576
commit a9c37d2ad5
4 changed files with 69 additions and 27 deletions

View file

@ -1,23 +1,18 @@
function! UpdateTags()
!ctags --recurse=yes ./src/
endfunction
function! RunDebug() function! RunDebug()
silent !ctags src/*.c src/shared/*.h UpdateTags()
silent !cmake -D CMAKE_BUILD_TYPE:STRING=Debug . !make BUILDMODE=debug all run_qt
!make && ./paysages
endfunction endfunction
function! RunRelease() function! RunRelease()
silent !ctags src/*.c src/shared/*.h UpdateTags()
silent !cmake -D CMAKE_BUILD_TYPE:STRING=Release . !make BUILDMODE=debug all run_qt
!make && ./paysages
endfunction endfunction
function! RunProfile() map <silent> <S-F9> :call RunDebug()<CR>
silent !ctags src/*.c src/shared/*.h map <silent> <S-F10> :call RunRelease()<CR>
silent !cmake -D CMAKE_BUILD_TYPE:STRING=Profile . map <silent> <F11> :!make tests<CR>
!make && ./paysages && gprof
endfunction
map <silent> <F9> :call RunDebug()<CR>
map <silent> <C-F9> :call RunProfile()<CR>
map <silent> <A-F9> :call RunRelease()<CR>
map <silent> <F10> :!eog output/resultaa.png<CR>

View file

@ -421,16 +421,13 @@ double euclidGet2DAngle(double x, double y)
{ {
return 0.0; return 0.0;
} }
else if (y < 0.0)
{
return 3.0 * M_PI_2;
}
else else
{ {
if (y < 0.0) return M_PI_2;
{
return 3.0 * M_PI_2;
}
else
{
return M_PI_2;
}
} }
} }
@ -443,7 +440,7 @@ double euclidGet2DAngle(double x, double y)
{ {
ret = M_PI - ret; ret = M_PI - ret;
} }
return fmod(ret, 2.0 * M_PI); return ret < 0.0 ? ret + 2.0 * M_PI : ret;
} }
Vector3 euclidGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right) Vector3 euclidGetNormalFromTriangle(Vector3 center, Vector3 bottom, Vector3 right)

View file

@ -1,9 +1,12 @@
#ifndef _PAYSAGES_TESTING_COMMON_H_ #ifndef _PAYSAGES_TESTING_COMMON_H_
#define _PAYSAGES_TESTING_COMMON_H_ #define _PAYSAGES_TESTING_COMMON_H_
#include <stdlib.h>
#include <stdio.h>
#include <check.h> #include <check.h>
#include <stdarg.h> #include <stdarg.h>
#include <math.h> #include <math.h>
#include <string.h>
static inline void _add_methods_to_case(TCase* tc, ...) static inline void _add_methods_to_case(TCase* tc, ...)
{ {
@ -33,8 +36,24 @@ static inline int _double_not_equals(double x, double y)
return fabs(x - y) >= 0.00000000001; return fabs(x - y) >= 0.00000000001;
} }
#define _ck_assert_double(F, X, O, Y) ck_assert_msg(F(X, Y), "Assertion '"#X#O#Y"' failed: "#X"==%f, "#Y"==%f", X, Y) #define _ck_assert_double(F, X, O, Y) ck_assert_msg(F(X, Y), "Assertion '"#X#O#Y"' failed: "#X"=%f, "#Y"=%f", X, Y)
#define ck_assert_double_eq(X, Y) _ck_assert_double(_double_equals, X, ==, Y) #define ck_assert_double_eq(X, Y) _ck_assert_double(_double_equals, X, ==, Y)
#define ck_assert_double_ne(X, Y) _ck_assert_double(_double_not_equals, X, !=, Y) #define ck_assert_double_ne(X, Y) _ck_assert_double(_double_not_equals, X, !=, Y)
/***** Generic comparison assertions *****/
#define DEFINE_COMPARE_ASSERT(_type_, _cmpfunc_, _strfunc_) \
static inline int _ck_gen_##_type_##_cmp(_type_ X, _type_ Y) { \
return _cmpfunc_(X, Y); \
} \
static inline char* _ck_gen_##_type_##_str(char* buffer, _type_ X) { \
_strfunc_(X, buffer, 99); \
buffer[100] = '\0'; \
return buffer; \
}
#define ck_assert_generic_eq(_type_, X, Y) ck_assert_msg(_ck_gen_##_type_##_cmp(X, Y) == 0, "Assertion '"#X"=="#Y"' failed : "#X"=%s, "#Y"=%s", _ck_gen_##_type_##_str(_ck_gen_strbuf1, X), _ck_gen_##_type_##_str(_ck_gen_strbuf2, Y))
static char _ck_gen_strbuf1[101];
static char _ck_gen_strbuf2[101];
#endif #endif

View file

@ -1,6 +1,16 @@
#include "testing/common.h" #include "testing/common.h"
#include "rendering/tools/euclid.h" #include "rendering/tools/euclid.h"
static inline int _Vector3_cmp(Vector3 v1, Vector3 v2)
{
return fabs(v1.x - v2.z) >= 0.00000000001 && fabs(v1.y - v2.y) >= 0.00000000001 && fabs(v1.z - v2.z) >= 0.00000000001;
}
static inline void _Vector3_str(Vector3 v, char* buffer, int length)
{
snprintf(buffer, length, "(%f,%f,%f)", v.x, v.y, v.z);
}
DEFINE_COMPARE_ASSERT(Vector3, _Vector3_cmp, _Vector3_str);
START_TEST(test_euclid_angles) START_TEST(test_euclid_angles)
{ {
ck_assert_double_eq(euclidGet2DAngle(0.0, 0.0), 0.0); ck_assert_double_eq(euclidGet2DAngle(0.0, 0.0), 0.0);
@ -28,4 +38,25 @@ START_TEST(test_euclid_angles)
} }
END_TEST END_TEST
TEST_CASE(euclid, test_euclid_angles) START_TEST(test_vectors)
{
Vector3 v1, v2, v3;
double d1, d2;
/* Test scaling */
v1.x = 0.0; v1.y = -4.3; v1.z = 8.2;
v2.x = 0.0; v2.y = -8.6; v2.z = 16.4;
v3.x = 0.0; v3.y = 2.15; v3.z = -4.1;
ck_assert_generic_eq(Vector3, v3Scale(v1, 2.0), v2);
ck_assert_generic_eq(Vector3, v3Scale(v1, -0.5), v3);
/* Test euler angles */
v1.x = v1.y = v1.z = 0.5;
v3ToEuler(v1, &d1, &d2);
ck_assert_double_eq(d1, M_PI_4);
ck_assert_double_eq(d2, M_PI_2 - 0.955316618125);
}
END_TEST
TEST_CASE(euclid, test_euclid_angles, test_vectors)