File: NSLFitTest.cpp

package info (click to toggle)
labplot 2.12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 78,528 kB
  • sloc: cpp: 241,047; ansic: 6,324; python: 915; xml: 400; yacc: 237; sh: 221; awk: 35; makefile: 11
file content (66 lines) | stat: -rw-r--r-- 2,000 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
	File                 : NSLFitTest.cpp
	Project              : LabPlot
	Description          : NSL Tests for fitting
	--------------------------------------------------------------------
	SPDX-FileCopyrightText: 2019 Stefan Gerlach <stefan.gerlach@uni.kn>

	SPDX-License-Identifier: GPL-2.0-or-later
*/

#include "NSLFitTest.h"

extern "C" {
#include "backend/nsl/nsl_fit.h"
}

// ##############################################################################
// #################  bound test
// ##############################################################################

const int N = 11;
const double data_unbound[] = {-4, -3, -2, -1, -.1, 0, .1, 1, 2, 3, 4};
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};
const double data_bound[] = {-1, -.99, -.5, 0, .49, .5, .51, 1, 1.5, 1.99, 2};
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};

void NSLFitTest::testBounds() {
	int i;
	for (i = 0; i < N; i++) {
		double x = nsl_fit_map_bound(data_unbound[i], -1, 2);
		//		printf("%g -> %.15g\n", data_unbound[i], x);
		QCOMPARE(x, result_bound[i]);
	}

	for (i = 0; i < N; ++i) {
		double x = nsl_fit_map_unbound(data_bound[i], -1, 2);
		//		printf("%g -> %.15g\n", data_bound[i], x);
		QCOMPARE(x, result_unbound[i]);
	}
}

// ##############################################################################
// #################  performance
// ##############################################################################

QTEST_MAIN(NSLFitTest)