mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-15 07:10:37 +08:00
Test application now takes 'seed' and 'repeat' command-line args
This commit is contained in:
parent
e05f29191e
commit
5abaaf9688
@ -90,11 +90,13 @@ template<typename MatrixType> void adjoint(const MatrixType& m)
|
||||
|
||||
void EigenTest::testAdjoint()
|
||||
{
|
||||
adjoint(Matrix<float, 1, 1>());
|
||||
adjoint(Matrix4cd());
|
||||
adjoint(MatrixXcf(3, 3));
|
||||
adjoint(MatrixXi(8, 12));
|
||||
adjoint(MatrixXd(20, 20));
|
||||
REPEAT {
|
||||
adjoint(Matrix<float, 1, 1>());
|
||||
adjoint(Matrix4cd());
|
||||
adjoint(MatrixXcf(3, 3));
|
||||
adjoint(MatrixXi(8, 12));
|
||||
adjoint(MatrixXd(20, 20));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Eigen
|
||||
|
@ -136,11 +136,13 @@ template<typename MatrixType> void basicStuff(const MatrixType& m)
|
||||
|
||||
void EigenTest::testBasicStuff()
|
||||
{
|
||||
basicStuff(Matrix<float, 1, 1>());
|
||||
basicStuff(Matrix4cd());
|
||||
basicStuff(MatrixXcf(3, 3));
|
||||
basicStuff(MatrixXi(8, 12));
|
||||
basicStuff(MatrixXd(20, 20));
|
||||
REPEAT {
|
||||
basicStuff(Matrix<float, 1, 1>());
|
||||
basicStuff(Matrix4cd());
|
||||
basicStuff(MatrixXcf(3, 3));
|
||||
basicStuff(MatrixXi(8, 12));
|
||||
basicStuff(MatrixXd(20, 20));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Eigen
|
||||
|
@ -25,14 +25,79 @@
|
||||
|
||||
#include "main.h"
|
||||
|
||||
Eigen::EigenTest::EigenTest()
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int t = (unsigned int) time(NULL);
|
||||
qDebug() << "Initializing random number generator with seed"
|
||||
<< t;
|
||||
srand(t);
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
bool has_set_repeat = false;
|
||||
bool has_set_seed = false;
|
||||
bool want_help = false;
|
||||
unsigned int seed;
|
||||
int repeat;
|
||||
|
||||
QStringList args = QCoreApplication::instance()->arguments();
|
||||
args.takeFirst(); // throw away the first argument (path to executable)
|
||||
foreach(QString arg, args)
|
||||
{
|
||||
if(arg.startsWith("r"))
|
||||
{
|
||||
if(has_set_repeat)
|
||||
{
|
||||
qDebug() << "Argument" << arg << "conflicting with a former argument";
|
||||
return 1;
|
||||
}
|
||||
repeat = arg.remove(0, 1).toInt();
|
||||
has_set_repeat = true;
|
||||
if(repeat <= 0)
|
||||
{
|
||||
qDebug() << "Invalid \'repeat\' value" << arg;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(arg.startsWith("s"))
|
||||
{
|
||||
if(has_set_seed)
|
||||
{
|
||||
qDebug() << "Argument" << arg << "conflicting with a former argument";
|
||||
return 1;
|
||||
}
|
||||
bool ok;
|
||||
seed = arg.remove(0, 1).toUInt(&ok);
|
||||
has_set_seed = true;
|
||||
if(!ok)
|
||||
{
|
||||
qDebug() << "Invalid \'seed\' value" << arg;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(arg == "h" || arg == "-h" || arg.contains("help", Qt::CaseInsensitive))
|
||||
{
|
||||
want_help = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << "Invalid command-line argument" << arg;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(want_help)
|
||||
{
|
||||
qDebug() << "This test application takes the following optional arguments:";
|
||||
qDebug() << " rN Repeat each test N times (default:" << DEFAULT_REPEAT << ")";
|
||||
qDebug() << " sN Use N as seed for random numbers (default: based on current time)";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(!has_set_seed) seed = (unsigned int) time(NULL);
|
||||
if(!has_set_repeat) repeat = DEFAULT_REPEAT;
|
||||
|
||||
qDebug() << "Initializing random number generator with seed" << seed;
|
||||
srand(seed);
|
||||
qDebug() << "Repeating each test" << repeat << "times";
|
||||
|
||||
Eigen::EigenTest test(repeat);
|
||||
return QTest::qExec(&test, 1, argv);
|
||||
}
|
||||
|
||||
QTEST_APPLESS_MAIN(Eigen::EigenTest)
|
||||
|
||||
#include "main.moc"
|
||||
|
@ -32,6 +32,9 @@
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
#define DEFAULT_REPEAT 50
|
||||
#define REPEAT for(int repeat_iteration = 0; repeat_iteration < m_repeat; repeat_iteration++)
|
||||
|
||||
namespace Eigen {
|
||||
|
||||
class EigenTest : public QObject
|
||||
@ -39,11 +42,14 @@ class EigenTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
EigenTest();
|
||||
EigenTest(int repeat) : m_repeat(repeat) {}
|
||||
|
||||
private slots:
|
||||
void testBasicStuff();
|
||||
void testAdjoint();
|
||||
|
||||
protected:
|
||||
int m_repeat;
|
||||
};
|
||||
|
||||
} // end namespace Eigen
|
||||
|
Loading…
Reference in New Issue
Block a user