File indexing completed on 2024-04-21 14:49:25

0001 /***************************************************************************
0002     File                 : CommonTest.h
0003     Project              : LabPlot
0004     Description          : General test class
0005     --------------------------------------------------------------------
0006     Copyright            : (C) 2019 Stefan Gerlach (stefan.gerlach@uni.kn)
0007  ***************************************************************************/
0008 
0009 /***************************************************************************
0010  *                                                                         *
0011  *  This program is free software; you can redistribute it and/or modify   *
0012  *  it under the terms of the GNU General Public License as published by   *
0013  *  the Free Software Foundation; either version 2 of the License, or      *
0014  *  (at your option) any later version.                                    *
0015  *                                                                         *
0016  *  This program is distributed in the hope that it will be useful,        *
0017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
0018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
0019  *  GNU General Public License for more details.                           *
0020  *                                                                         *
0021  *   You should have received a copy of the GNU General Public License     *
0022  *   along with this program; if not, write to the Free Software           *
0023  *   Foundation, Inc., 51 Franklin Street, Fifth Floor,                    *
0024  *   Boston, MA  02110-1301  USA                                           *
0025  *                                                                         *
0026  ***************************************************************************/
0027 #ifndef COMMONTEST_H
0028 #define COMMONTEST_H
0029 
0030 #include <QtTest>
0031 #include <backend/lib/macros.h> // DEBUG()
0032 
0033 extern "C" {
0034 #include <gsl/gsl_math.h>
0035 }
0036 
0037 class CommonTest : public QObject {
0038     Q_OBJECT
0039 
0040 private slots:
0041     void initTestCase();
0042 protected:
0043     // compare floats with given delta
0044     // delta - relative error
0045     static inline void FuzzyCompare(double actual, double expected, double delta = 1.e-12) {
0046         if (fabs(expected) < delta)
0047             QVERIFY(fabs(actual) < delta);
0048         else {
0049             DEBUG(std::setprecision(15) << actual - fabs(actual)*delta << " <= " << expected << " <= " << actual + fabs(actual)*delta);
0050             QVERIFY(!gsl_fcmp(actual, expected, delta));
0051         }
0052     }
0053 };
0054 #endif