Added unit tests for vector relational

This commit is contained in:
Christophe Riccio 2011-01-15 22:08:31 +00:00
parent ac7e851692
commit c891092425
3 changed files with 176 additions and 25 deletions

View File

@ -33,11 +33,10 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT((
detail::type<T>::is_float ||
detail::type<T>::is_int ||
detail::type<T>::is_uint) && detail::is_vector<vecType<T> >::_YES,
"'lessThan' only accept numbers");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'lessThan', GLM vector types required");
GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
"Invalid template instantiation of 'lessThan', GLM vector types required floating-point or integer value types vectors");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -54,11 +53,10 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT((
detail::type<T>::is_float ||
detail::type<T>::is_int ||
detail::type<T>::is_uint) && detail::is_vector<vecType<T> >::_YES,
"'lessThanEqual' only accept numbers");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'lessThanEqual', GLM vector types required");
GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
"Invalid template instantiation of 'lessThanEqual', GLM vector types required floating-point or integer value types vectors");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -75,11 +73,10 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT((
detail::type<T>::is_float ||
detail::type<T>::is_int ||
detail::type<T>::is_uint) && detail::is_vector<vecType<T> >::_YES,
"'greaterThan' only accept numbers");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'greaterThan', GLM vector types required");
GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
"Invalid template instantiation of 'greaterThan', GLM vector types required floating-point or integer value types vectors");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -96,11 +93,10 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT((
detail::type<T>::is_float ||
detail::type<T>::is_int ||
detail::type<T>::is_uint) && detail::is_vector<vecType<T> >::_YES,
"'greaterThanEqual' only accept numbers");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'greaterThanEqual', GLM vector types required");
GLM_STATIC_ASSERT(detail::is_bool<T>::_NO,
"Invalid template instantiation of 'greaterThanEqual', GLM vector types required floating-point or integer value types vectors");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -117,7 +113,8 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES, "'equal' only accept GLM vectors");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'equal', GLM vector types required");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -134,7 +131,8 @@ namespace glm
vecType<T> const & y
)
{
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES, "'notEqual' only accept GLM vectors");
GLM_STATIC_ASSERT(detail::is_vector<vecType<T> >::_YES,
"Invalid template instantiation of 'notEqual', GLM vector types required");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -147,7 +145,8 @@ namespace glm
template <template <typename> class vecType>
inline bool any(vecType<bool> const & v)
{
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES, "'any' only accept GLM boolean vectors");
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
"Invalid template instantiation of 'any', GLM boolean vector types required");
bool Result = false;
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -160,7 +159,8 @@ namespace glm
template <template <typename> class vecType>
inline bool all(vecType<bool> const & v)
{
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES, "'all' only accept GLM boolean vectors");
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
"Invalid template instantiation of 'all', GLM boolean vector types required");
bool Result = true;
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)
@ -173,7 +173,8 @@ namespace glm
template <template <typename> class vecType>
inline vecType<bool> not_(vecType<bool> const & v)
{
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES, "'not_' only accept GLM boolean vectors");
GLM_STATIC_ASSERT(detail::is_vector<vecType<bool> >::_YES,
"Invalid template instantiation of 'not_', GLM vector types required");
typename vecType<bool>::bool_type Result(vecType<bool>::null);
for(typename vecType<bool>::size_type i = 0; i < vecType<bool>::value_size(); ++i)

View File

@ -14,5 +14,7 @@ glmCreateTestGTC(core_type_vec1)
glmCreateTestGTC(core_type_vec2)
glmCreateTestGTC(core_type_vec3)
glmCreateTestGTC(core_type_vec4)
glmCreateTestGTC(core_vector_relational)

View File

@ -0,0 +1,148 @@
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2010 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2011-01-15
// Updated : 2011-01-15
// Licence : This source is under MIT licence
// File : test/gtx/simd-mat4.cpp
///////////////////////////////////////////////////////////////////////////////////////////////////
#define GLM_INSTRUCTION_SET GLM_PLATFORM_SSE3 | GLM_PLATFORM_SSE2
#include <glm/glm.hpp>
int test_static_assert()
{
//glm::lessThan(glm::mat4(0), glm::mat4(4));
return 0;
}
int test_lessThan_vec2()
{
glm::bvec2 O = glm::bvec2(true, false);
glm::bvec2 A = glm::lessThan(glm::vec2(0, 6), glm::vec2(4, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec2 B = glm::lessThan(glm::ivec2(0, 6), glm::ivec2(4, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec2 C = glm::lessThan(glm::uvec2(0, 6), glm::uvec2(4, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_lessThan_vec3()
{
glm::bvec3 O = glm::bvec3(true, true, false);
glm::bvec3 A = glm::lessThan(glm::vec3(0, 1, 6), glm::vec3(4, 5, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec3 B = glm::lessThan(glm::ivec3(0, 1, 6), glm::ivec3(4, 5, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec3 C = glm::lessThan(glm::uvec3(0, 1, 6), glm::uvec3(4, 5, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_lessThan_vec4()
{
glm::bvec4 O = glm::bvec4(true, true, false, false);
glm::bvec4 A = glm::lessThan(glm::vec4(0, 1, 6, 7), glm::vec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, A)));
glm::bvec4 B = glm::lessThan(glm::ivec4(0, 1, 6, 7), glm::ivec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, B)));
glm::bvec4 C = glm::lessThan(glm::uvec4(0, 1, 6, 7), glm::uvec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec2()
{
glm::bvec2 O = glm::bvec2(false, true);
glm::bvec2 A = glm::greaterThanEqual(glm::vec2(0, 6), glm::vec2(4, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec2 B = glm::greaterThanEqual(glm::ivec2(0, 6), glm::ivec2(4, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec2 C = glm::greaterThanEqual(glm::uvec2(0, 6), glm::uvec2(4, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec3()
{
glm::bvec3 O = glm::bvec3(false, false, true);
glm::bvec3 A = glm::greaterThanEqual(glm::vec3(0, 1, 6), glm::vec3(4, 5, 2));
assert(glm::all(glm::equal(O, A)));
glm::bvec3 B = glm::greaterThanEqual(glm::ivec3(0, 1, 6), glm::ivec3(4, 5, 2));
assert(glm::all(glm::equal(O, B)));
glm::bvec3 C = glm::greaterThanEqual(glm::uvec3(0, 1, 6), glm::uvec3(4, 5, 2));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_greaterThanEqual_vec4()
{
glm::bvec4 O = glm::bvec4(false, false, true, true);
glm::bvec4 A = glm::greaterThanEqual(glm::vec4(0, 1, 6, 7), glm::vec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, A)));
glm::bvec4 B = glm::greaterThanEqual(glm::ivec4(0, 1, 6, 7), glm::ivec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, B)));
glm::bvec4 C = glm::greaterThanEqual(glm::uvec4(0, 1, 6, 7), glm::uvec4(4, 5, 2, 3));
assert(glm::all(glm::equal(O, C)));
return 0;
}
int test_all()
{
assert(glm::all(glm::bvec2(true, true)));
assert(!glm::all(glm::bvec2(true, false)));
assert(!glm::all(glm::bvec2(false, false)));
assert(glm::all(glm::bvec3(true, true, true)));
assert(!glm::all(glm::bvec3(true, false, true)));
assert(!glm::all(glm::bvec3(false, false, false)));
assert(glm::all(glm::bvec4(true, true, true, true)));
assert(!glm::all(glm::bvec4(true, false, true, false)));
assert(!glm::all(glm::bvec4(false, false, false, false)));
return 0;
}
int main(int argc, void* argv[])
{
int Failed = 0;
Failed += test_static_assert();
Failed += test_lessThan_vec2();
Failed += test_lessThan_vec3();
Failed += test_lessThan_vec4();
Failed += test_greaterThanEqual_vec2();
Failed += test_greaterThanEqual_vec3();
Failed += test_greaterThanEqual_vec4();
Failed += test_all();
return Failed;
}