File indexing completed on 2024-04-28 15:14:11
0001 /*************************************************************************** 0002 File : NSLFitTest.cpp 0003 Project : LabPlot 0004 Description : NSL Tests for fitting 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 "NSLFitTest.h" 0029 0030 extern "C" { 0031 #include "backend/nsl/nsl_fit.h" 0032 } 0033 0034 //############################################################################## 0035 //################# bound test 0036 //############################################################################## 0037 0038 const int N = 11; 0039 const double data_unbound[] = {-4, -3, -2, -1, -.1, 0, .1, 1, 2, 3, 4}; 0040 const double result_bound[] = {1.63520374296189, 0.288319987910199, -0.863946140238523, -0.762206477211845, 0.350249875029758, 0.5, 0.649750124970242, 1.76220647721184, 1.86394614023852, 0.711680012089801, -0.635203742961892}; 0041 const double data_bound[]={-1, -.99, -.5, 0, .49, .5, .51, 1, 1.5, 1.99, 2}; 0042 const double result_unbound[] = {-1.5707963267949, -1.45526202651066, -0.729727656226966, -0.339836909454122, -0.00666671605037044, 0, 0.00666671605037033, 0.339836909454122, 0.729727656226966, 1.45526202651066, 1.5707963267949}; 0043 0044 void NSLFitTest::testBounds() { 0045 int i; 0046 for (i = 0; i < N; i++) { 0047 double x = nsl_fit_map_bound(data_unbound[i], -1, 2); 0048 // printf("%g -> %.15g\n", data_unbound[i], x); 0049 QCOMPARE(x, result_bound[i]); 0050 } 0051 0052 for (i = 0; i < N; ++i) { 0053 double x = nsl_fit_map_unbound(data_bound[i], -1, 2); 0054 // printf("%g -> %.15g\n", data_bound[i], x); 0055 QCOMPARE(x, result_unbound[i]); 0056 } 0057 0058 } 0059 0060 //############################################################################## 0061 //################# performance 0062 //############################################################################## 0063 0064 QTEST_MAIN(NSLFitTest)