35 # define TMP "tmp.txt"
37 # define TMP "/tmp/tmp.txt"
44 #include <Base/Math/Vector2.hh>
45 #include <Base/Math/Vector3.hh>
46 #include <Base/Math/Vector4.hh>
47 #include <Base/Math/RGB.hh>
48 #include <Base/Math/RGBA.hh>
50 #include <Base/Math/Matrix2x2.hh>
51 #include <Base/Math/Matrix3x3.hh>
52 #include <Base/Math/Matrix3x4.hh>
53 #include <Base/Math/Matrix4x4.hh>
62 #define DISPVAL(_ARG) {string s(#_ARG); std::cout<<s<<" "<<endl<<_ARG<<endl;}
71 return ((
double)rand() / (
double)RAND_MAX);
79 T val = (T) ( rand1() * numeric_limits<T>::max());
88 for (
unsigned int i=0; (int)i<(
int)g_samples; i++){
89 RGBuc a(myrand<unsigned char>(), myrand<unsigned char>(), myrand<unsigned char>()), b;
93 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i<<
"/"<<g_samples<<
" with "<<endl
108 for (
unsigned int i=0; (int)i<(
int)g_samples; i++){
109 RGBAuc a(myrand<unsigned char>(), myrand<unsigned char>(), myrand<unsigned char>(), myrand<unsigned char>()), b;
113 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i<<
"/"<<g_samples<<
" with "<<endl
128 for (
unsigned int i=0; (int)i<(
int)g_samples; i++){
129 RGBAf a(myrand<float>(), myrand<float>(), myrand<float>(), myrand<float>()), b;
133 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i<<
"/"<<g_samples<<
" with "<<endl
148 for (
unsigned int i=0; (int)i<(
int)g_samples; i++){
149 RGBf a(myrand<float>(), myrand<float>(), myrand<float>()), b;
153 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i<<
"/"<<g_samples<<
" with "<<endl
164 template <
class TYPE,
class T>
165 void display(
const unsigned int samples=1)
171 <<
"TYPE="<<
typeid(TYPE).name()<<
" "
172 <<
"T="<<
typeid(T).name()<<
" "<<endl;
174 cout<<FUNCNAME<<
" "<<endl;
179 for (
unsigned int jj=0; (int)jj<(
int)a.GetNumElements(); jj++){
181 a.GetData()[jj]=numeric_limits<T>::min();
183 a.GetData()[jj]=numeric_limits<T>::max();
185 a.GetData()[jj]=(T)0;
187 a.GetData()[jj]=myrand<T>();
194 template <
class TYPE,
class T>
195 void check(
const unsigned int samples=1)
201 <<
"TYPE="<<
typeid(TYPE).name()<<
" "
202 <<
"T="<<
typeid(T).name()<<
" ";
208 for (
unsigned int i=0; i<samples; i++)
211 for (
unsigned int jj=0; (int)jj<(
int)a.GetNumElements(); jj++)
212 a.GetData()[jj]=myrand<T>();
218 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i+1<<
"/"<<samples<<
" with "<<endl
221 <<
"delta:"<<a-b<<endl
236 template <
class TYPE,
class T>
237 void checkWithDim2(
const unsigned int dim,
const unsigned int samples)
243 <<
"TYPE="<<
typeid(TYPE).name()<<
" "
244 <<
"T="<<
typeid(T).name()<<
" "
251 for (
unsigned int i=0; i<samples; i++)
254 a.newsize(dim, dim+1);
255 for (
unsigned int jj=0; (int)jj<(
int)a.GetNumElements(); jj++)
256 a.GetData()[jj]=myrand<T>();
261 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i+1<<
"/"<<samples<<
" with "<<endl
264 <<
"delta:"<<a-b<<endl
277 template <
class TYPE,
class T>
278 void checkWithDim1(
const unsigned int dim,
const unsigned int samples)
284 <<
"TYPE="<<
typeid(TYPE).name()<<
" "
285 <<
"T="<<
typeid(T).name()<<
" "
292 for (
unsigned int i=0; i<samples; i++)
296 for (
unsigned int jj=0; (int)jj<(
int)a.GetNumElements(); jj++)
297 a.GetData()[jj]=myrand<T>();
302 BIASERR(
"failed: Save/Load to "<<
TMP<<
" on sample "<<i+1<<
"/"<<samples<<
" with "<<endl
305 <<
"delta:"<<a-b<<endl
317 #define CHECK_TYPE( _TPLCLASS ) \
318 check< _TPLCLASS< unsigned char >, unsigned char >(); \
319 check< _TPLCLASS< char >, char >(); \
320 check< _TPLCLASS< int >, int >(); \
321 check< _TPLCLASS< unsigned short>, unsigned short >(); \
322 check< _TPLCLASS< int >, int >(); \
323 check< _TPLCLASS< float >, float >(); \
324 check< _TPLCLASS< double >, double >();
328 int main(
int argc,
char** argv)
333 cout<<
"CTEST_FULL_OUTPUT"<<endl;
336 cout<<
"started "<<argv[0]<<endl;
339 g_samples=atoi(argv[1]);
340 cout<<
"using "<<g_samples<<
" random samples for each instance."<<endl;
353 checkWithDim2< BIAS::Matrix<double>,
double> (7, g_samples);
354 checkWithDim2< BIAS::Matrix<float>,
float> (7, g_samples);
355 checkWithDim2< BIAS::Matrix<int>,
int> (7, g_samples);
356 checkWithDim2< BIAS::Matrix<unsigned char>,
unsigned char> (7, g_samples);
357 checkWithDim2< BIAS::Matrix<char >,
char> (7, g_samples);
358 checkWithDim2< BIAS::Matrix<unsigned short>,
unsigned short>(7, g_samples);
361 checkWithDim1< BIAS::Vector<double>,
double> (42, g_samples);
362 checkWithDim1< BIAS::Vector<float>,
float> (42, g_samples);
363 checkWithDim1< BIAS::Vector<int>,
int> (42, g_samples);
364 checkWithDim1< BIAS::Vector<unsigned char>,
unsigned char> (42, g_samples);
365 checkWithDim1< BIAS::Vector<char >,
char> (42, g_samples);
366 checkWithDim1< BIAS::Vector<unsigned short>,
unsigned short>(42, g_samples);
376 DISPVAL(
RGBuc (0, 255, 3));
377 DISPVAL(
RGBAuc(0, 255, 3, 4));
378 DISPVAL(
RGBf (1.f/3.f, -2.2f, 3.3f));
379 DISPVAL(
RGBAf(1.f/3.f, -2.2f, 3.3f, 4.4f));
383 cout<<
"test failed with result="<<g_result<<endl;
386 cout<<
"OK - test succeeded."<<endl;
class RGBAf is a synonym for a Vector3 of correct type
is a 'fixed size' quadratic matrix of dim.
class RGBAuc is asynonym for a Vector4 of corerct type
class RGBAf is asynonym for a Vector4 of correct type
#define TMP
Test Matrix I/O precision issues.
class Vector2 contains a Vector of dim.
class Vector4 contains a Vector of dim.
class RGBuc is a synonym for a Vector3 of correct type
is a 'fixed size' quadratic matrix of dim.
class Vector3 contains a Vector of fixed dim.
is a 'fixed size' rectangular matrix of dim.
is a 'fixed size' quadratic matrix of dim.