File indexing completed on 2024-04-28 03:48:20
0001 /* 0002 File : NSLSFBasicTest.cpp 0003 Project : LabPlot 0004 Description : NSL Tests for basic special functions 0005 -------------------------------------------------------------------- 0006 SPDX-FileCopyrightText: 2019 Stefan Gerlach <stefan.gerlach@uni.kn> 0007 0008 SPDX-License-Identifier: GPL-2.0-or-later 0009 */ 0010 0011 #include "NSLSFBasicTest.h" 0012 0013 #include "backend/nsl/nsl_sf_basic.h" 0014 0015 // ############################################################################## 0016 // ################# log2() tests 0017 // ############################################################################## 0018 void NSLSFBasicTest::testlog2_int_C99() { 0019 QBENCHMARK { 0020 for (unsigned int i = 1; i < 1e7; i++) 0021 Q_UNUSED((int)log2(i)); 0022 } 0023 } 0024 0025 void NSLSFBasicTest::testlog2_int() { 0026 for (unsigned int i = 1; i < 1e5; i++) { 0027 int result = nsl_sf_log2_int(i); 0028 QCOMPARE(result, (int)log2(i)); 0029 } 0030 0031 QBENCHMARK { 0032 for (unsigned int i = 1; i < 1e7; i++) 0033 nsl_sf_log2_int(i); 0034 } 0035 } 0036 void NSLSFBasicTest::testlog2_longlong() { 0037 #ifndef _MSC_VER /* not implemented yet */ 0038 for (unsigned long long i = 1; i < 1e5; i++) { 0039 int result = nsl_sf_log2_longlong(i); 0040 QCOMPARE(result, (int)log2(i)); 0041 } 0042 0043 QBENCHMARK { 0044 for (unsigned long long i = 1; i < 1e7; i++) 0045 nsl_sf_log2_longlong(i); 0046 } 0047 #endif 0048 } 0049 0050 void NSLSFBasicTest::testlog2_int2() { 0051 for (int i = 1; i < 1e5; i++) { 0052 int result = nsl_sf_log2_int2(i); 0053 QCOMPARE(result, (int)log2(i)); 0054 } 0055 0056 QBENCHMARK { 0057 for (int i = 1; i < 1e7; i++) 0058 nsl_sf_log2_int2(i); 0059 } 0060 } 0061 0062 void NSLSFBasicTest::testlog2_int3() { 0063 for (unsigned int i = 1; i < 1e5; i++) { 0064 int result = nsl_sf_log2_int3(i); 0065 QCOMPARE(result, (int)log2(i)); 0066 } 0067 0068 QBENCHMARK { 0069 for (unsigned int i = 1; i < 1e7; i++) 0070 nsl_sf_log2_int3(i); 0071 } 0072 } 0073 0074 void NSLSFBasicTest::testlog2p1_int() { 0075 for (int i = 1; i < 1e5; i++) { 0076 int result = nsl_sf_log2p1_int(i); 0077 QCOMPARE(result, (int)log2(i) + 1); 0078 } 0079 0080 QBENCHMARK { 0081 for (int i = 1; i < 1e7; i++) 0082 nsl_sf_log2p1_int(i); 0083 } 0084 } 0085 0086 QTEST_MAIN(NSLSFBasicTest)