mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-17 18:09:55 +08:00
port TestNumericTraits to QTestLib. This revealed some shortcomings in tvmet's infrastructure,
in particular it lacks adequate fuzzy compares. will port that from eigen1.
This commit is contained in:
parent
b6dedaf745
commit
d62af65d7f
@ -11,6 +11,7 @@ INCLUDE_DIRECTORIES( ${QT_INCLUDE_DIR} )
|
||||
SET(testsuite_SOURCES
|
||||
main.cpp
|
||||
selftest.cpp
|
||||
testnumerictraits.cpp
|
||||
# TestNumericTraits.h TestNumericTraits.cc
|
||||
# TestNumericTraitsComplex.h TestNumericTraitsComplex.cc
|
||||
# TestConstruction.h TestConstruction.cc
|
||||
|
@ -43,6 +43,7 @@ public:
|
||||
|
||||
private slots:
|
||||
void selfTest();
|
||||
void testNumericTraits();
|
||||
};
|
||||
|
||||
#endif // EIGEN_TESTSUITE_MAIN_H
|
||||
|
@ -53,11 +53,11 @@ template<typename T> static void basics2()
|
||||
2,5,8,
|
||||
3,6,9;
|
||||
|
||||
assert(v1(0) == T(1) && v1(1) == T(2) && v1(2) == T(3));
|
||||
QVERIFY(v1(0) == T(1) && v1(1) == T(2) && v1(2) == T(3));
|
||||
|
||||
assert(m1(0,0) == T(1) && m1(0,1) == T(4) && m1(0,2) == T(7) &&
|
||||
m1(1,0) == T(2) && m1(1,1) == T(5) && m1(1,2) == T(8) &&
|
||||
m1(2,0) == T(3) && m1(2,1) == T(6) && m1(2,2) == T(9));
|
||||
QVERIFY(m1(0,0) == T(1) && m1(0,1) == T(4) && m1(0,2) == T(7) &&
|
||||
m1(1,0) == T(2) && m1(1,1) == T(5) && m1(1,2) == T(8) &&
|
||||
m1(2,0) == T(3) && m1(2,1) == T(6) && m1(2,2) == T(9));
|
||||
}
|
||||
|
||||
void TvmetTestSuite::selfTest()
|
||||
@ -69,10 +69,8 @@ void TvmetTestSuite::selfTest()
|
||||
basics2<int> ();
|
||||
basics2<double> ();
|
||||
|
||||
#ifdef EIGEN_USE_COMPLEX
|
||||
basics1<complex<float>, 4> ();
|
||||
basics1<complex<double>, 4> ();
|
||||
basics2<complex<int> > ();
|
||||
basics2<complex<double> > ();
|
||||
#endif
|
||||
}
|
||||
|
125
tvmet-1.7.1/testsuite/testnumerictraits.cpp
Normal file
125
tvmet-1.7.1/testsuite/testnumerictraits.cpp
Normal file
@ -0,0 +1,125 @@
|
||||
/* This file is part of Eigen, a C++ template library for linear algebra
|
||||
* Copyright (C) 2007 Benoit Jacob <jacob@math.jussieu.fr>
|
||||
*
|
||||
* Based on Tvmet source code, http://tvmet.sourceforge.net,
|
||||
* Copyright (C) 2001 - 2003 Olaf Petzold <opetzold@users.sourceforge.net>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* $Id: SelfTest.cc,v 1.1 2004/04/24 11:55:15 opetzold Exp $
|
||||
*/
|
||||
|
||||
#include "main.h"
|
||||
|
||||
template<typename T, int n> struct TestNumericTraits
|
||||
{
|
||||
const T m_real;
|
||||
const T m_imag;
|
||||
const T m_conj;
|
||||
const T m_abs_Q1;
|
||||
|
||||
void real()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type real_type;
|
||||
real_type r = tvmet::NumericTraits<T>::real(m_real);
|
||||
QVERIFY( r == m_real );
|
||||
}
|
||||
|
||||
void imag()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type real_type;
|
||||
real_type r = tvmet::NumericTraits<T>::real(m_real);
|
||||
QVERIFY( r == m_real );
|
||||
}
|
||||
|
||||
void conj()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type conj_type;
|
||||
conj_type r = tvmet::NumericTraits<T>::conj(m_conj);
|
||||
QVERIFY( r == m_conj );
|
||||
}
|
||||
|
||||
void abs()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type r1 = tvmet::NumericTraits<T>::abs(m_abs_Q1);
|
||||
value_type r2 = tvmet::NumericTraits<T>::abs(-m_abs_Q1);
|
||||
QVERIFY( r1 == m_abs_Q1 );
|
||||
QVERIFY( r2 == m_abs_Q1 );
|
||||
}
|
||||
|
||||
void sqrt()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type r1 = tvmet::NumericTraits<T>::sqrt(m_real);
|
||||
value_type r2 = tvmet::NumericTraits<T>::sqrt(m_imag);
|
||||
QVERIFY( r1 == 2 );
|
||||
QVERIFY( r2 == 3 );
|
||||
}
|
||||
|
||||
void norm1()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type r = tvmet::NumericTraits<T>::norm_1(m_real);
|
||||
QVERIFY( r == tvmet::NumericTraits<T>::abs(m_real) );
|
||||
}
|
||||
|
||||
void norm2()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type r = tvmet::NumericTraits<T>::norm_2(m_real);
|
||||
QVERIFY( r == tvmet::NumericTraits<T>::abs(m_real) );
|
||||
}
|
||||
|
||||
void normInf()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type r = tvmet::NumericTraits<T>::norm_inf(m_real);
|
||||
QVERIFY( r == tvmet::NumericTraits<T>::abs(m_real) );
|
||||
}
|
||||
|
||||
void equals()
|
||||
{
|
||||
typedef typename tvmet::NumericTraits<T>::base_type value_type;
|
||||
value_type lhs, rhs;
|
||||
lhs = rhs = 47;
|
||||
QVERIFY( true == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
||||
// a not very intelligent test
|
||||
rhs += 1;
|
||||
QVERIFY( false == tvmet::NumericTraits<T>::equals(lhs,rhs) );
|
||||
}
|
||||
|
||||
|
||||
TestNumericTraits() : m_real(4), m_imag(9), m_conj(16), m_abs_Q1(7)
|
||||
{
|
||||
real();
|
||||
imag();
|
||||
conj();
|
||||
abs();
|
||||
sqrt();
|
||||
norm1();
|
||||
norm2();
|
||||
normInf();
|
||||
equals();
|
||||
}
|
||||
};
|
||||
|
||||
void TvmetTestSuite::testNumericTraits()
|
||||
{
|
||||
TestNumericTraits<double,1>();
|
||||
TestNumericTraits<int, 2>();
|
||||
TestNumericTraits<float, 3>();
|
||||
TestNumericTraits<double,4>();
|
||||
}
|
Loading…
Reference in New Issue
Block a user