File indexing completed on 2024-05-05 16:00:21

0001 /***************************************************************************
0002     File                 : NSLSFBasicTest.cpp
0003     Project              : LabPlot
0004     Description          : NSL Tests for basic special functions
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 
0028 #include "NSLSFBasicTest.h"
0029 
0030 extern "C" {
0031 #include "backend/nsl/nsl_sf_basic.h"
0032 }
0033 
0034 //##############################################################################
0035 //#################  log2() tests
0036 //##############################################################################
0037 void NSLSFBasicTest::testlog2_int_C99() {
0038     QBENCHMARK {
0039         for (unsigned int i = 1; i < 1e7; i++)
0040             Q_UNUSED((int)log2(i));
0041     }
0042 }
0043 
0044 void NSLSFBasicTest::testlog2_int() {
0045     for (unsigned int i = 1; i < 1e5; i++) {
0046         int result = nsl_sf_log2_int(i);
0047         QCOMPARE(result, (int)log2(i));
0048     }
0049 
0050     QBENCHMARK {
0051         for (unsigned int i = 1; i < 1e7; i++)
0052             nsl_sf_log2_int(i);
0053     }
0054 }
0055 void NSLSFBasicTest::testlog2_longlong() {
0056 #ifndef _MSC_VER    /* not implemented yet */
0057     for (unsigned long long i = 1; i < 1e5; i++) {
0058         int result = nsl_sf_log2_longlong(i);
0059         QCOMPARE(result, (int)log2(i));
0060     }
0061 
0062     QBENCHMARK {
0063         for (unsigned long long i = 1; i < 1e7; i++)
0064             nsl_sf_log2_longlong(i);
0065     }
0066 #endif
0067 }
0068 
0069 
0070 void NSLSFBasicTest::testlog2_int2() {
0071     for (int i = 1; i < 1e5; i++) {
0072         int result = nsl_sf_log2_int2(i);
0073         QCOMPARE(result, (int)log2(i));
0074     }
0075 
0076     QBENCHMARK {
0077         for (int i = 1; i < 1e7; i++)
0078             nsl_sf_log2_int2(i);
0079     }
0080 }
0081 
0082 void NSLSFBasicTest::testlog2_int3() {
0083     for (unsigned int i = 1; i < 1e5; i++) {
0084         int result = nsl_sf_log2_int3(i);
0085         QCOMPARE(result, (int)log2(i));
0086     }
0087 
0088     QBENCHMARK {
0089         for (unsigned int i = 1; i < 1e7; i++)
0090             nsl_sf_log2_int3(i);
0091     }
0092 }
0093 
0094 void NSLSFBasicTest::testlog2p1_int() {
0095     for (int i = 1; i < 1e5; i++) {
0096         int result = nsl_sf_log2p1_int(i);
0097         QCOMPARE(result, (int)log2(i) + 1);
0098     }
0099 
0100     QBENCHMARK {
0101         for (int i = 1; i < 1e7; i++)
0102             nsl_sf_log2p1_int(i);
0103     }
0104 
0105 }
0106 
0107 QTEST_MAIN(NSLSFBasicTest)