diff --git a/test/adjoint.cpp b/test/adjoint.cpp index 2d6aac535..d34137c10 100644 --- a/test/adjoint.cpp +++ b/test/adjoint.cpp @@ -90,11 +90,13 @@ template void adjoint(const MatrixType& m) void EigenTest::testAdjoint() { - adjoint(Matrix()); - adjoint(Matrix4cd()); - adjoint(MatrixXcf(3, 3)); - adjoint(MatrixXi(8, 12)); - adjoint(MatrixXd(20, 20)); + REPEAT { + adjoint(Matrix()); + adjoint(Matrix4cd()); + adjoint(MatrixXcf(3, 3)); + adjoint(MatrixXi(8, 12)); + adjoint(MatrixXd(20, 20)); + } } } // namespace Eigen diff --git a/test/basicstuff.cpp b/test/basicstuff.cpp index babddb670..f28477a68 100644 --- a/test/basicstuff.cpp +++ b/test/basicstuff.cpp @@ -136,11 +136,13 @@ template void basicStuff(const MatrixType& m) void EigenTest::testBasicStuff() { - basicStuff(Matrix()); - basicStuff(Matrix4cd()); - basicStuff(MatrixXcf(3, 3)); - basicStuff(MatrixXi(8, 12)); - basicStuff(MatrixXd(20, 20)); + REPEAT { + basicStuff(Matrix()); + basicStuff(Matrix4cd()); + basicStuff(MatrixXcf(3, 3)); + basicStuff(MatrixXi(8, 12)); + basicStuff(MatrixXd(20, 20)); + } } } // namespace Eigen diff --git a/test/main.cpp b/test/main.cpp index e1272087a..3a63653a4 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -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" diff --git a/test/main.h b/test/main.h index 3d90a2f48..4bb7b1b15 100644 --- a/test/main.h +++ b/test/main.h @@ -32,6 +32,9 @@ #include #include +#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