File indexing completed on 2024-05-05 03:48:44

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