File: RangeTest.cpp

package info (click to toggle)
labplot 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 70,348 kB
  • sloc: cpp: 145,806; ansic: 4,534; python: 881; yacc: 540; xml: 357; sh: 185; awk: 35; makefile: 7
file content (92 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
    File                 : RangeTest.cpp
    Project              : LabPlot
    Description          : Tests for Range
    --------------------------------------------------------------------
    SPDX-FileCopyrightText: 2021 Stefan Gerlach <stefan.gerlach@uni.kn>

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

#include "RangeTest.h"
#include "backend/lib/Range.h"

//**********************************************************
//****************** Function tests ************************
//**********************************************************

void RangeTest::testNiceExtend() {
	QVector< QPair<Range<double>, Range<double>> > tests{
		{{0.,.95},{0.,1.}}, {{0,.91},{0.,1.}}, {{0,.9},{0.,.9}},
		{{0.,.85},{0.,.9}}, {{0,.81},{0.,.9}}, {{0,.71},{0.,.8}},
		{{0,.46},{0.,.5}}, {{0.,.41},{0.,.45}}, {{0,.36},{0.,.4}},
		{{0,.19},{0.,.2}}, {{0.,.17},{0.,.2}}, {{0,995.},{0, 1000.}},
		{{0.75, 2.25},{0.5, 2.5}}, {{0,.21},{0.,.25}}
	};
	QVector< QPair<Range<double>, Range<double>> > tests2{	// QCOMPARE is too strict
		{{0.,.13},{0.,.15}}, {{0,.15},{0.,.15}},
		{{0.,.61},{0.,.7}}, {{0,.51},{0.,.6}}, {{0,.31},{0.,.35}},
		{{0.,.26},{0.,.3}}
	};

	for (auto& test : tests) {
		DEBUG(Q_FUNC_INFO << ", " << test.first.toStdString())
		test.first.niceExtend();
		//WARN(std::setprecision(19) << test.first.start() << " == " << test.second.start())
		//WARN(std::setprecision(19) << test.first.end() << " == " << test.second.end())
		QCOMPARE(test.first, test.second);
	}
	for (auto& test : tests2) {
		DEBUG(Q_FUNC_INFO << ", " << test.first.toStdString())
		test.first.niceExtend();
		//WARN(std::setprecision(19) << test.first.start() << " == " << test.second.start())
		//WARN(std::setprecision(19) << test.first.end() << " == " << test.second.end())
		FuzzyCompare(test.first.start(), test.second.start(), DBL_EPSILON);
		FuzzyCompare(test.first.end(), test.second.end(), 1.e-15);
	}
}


void RangeTest::testTickCount() {

	const QVector<QPair<Range<double>, int>> tests{
		{{0., 1.}, 6}, {{0., 0.01}, 6}, {{0., 100.}, 6},
		{{0., 2.}, 5}, {{0., 3.}, 4}, {{0., 4.}, 5}, {{0., 5.}, 6},
		{{0., 6.}, 4}, {{0., 7.}, 8}, {{0., 8.}, 5}, {{0., 9.}, 4},
		{{1.6, 2.2}, 4}, {{1.3, 2.7}, 8}, {{0., 3.2}, 5}, {{0.4, 2.}, 5},
		{{0.5, 2.5}, 5}
		// size=29,41 should not happen when nice extended
	};

	for (auto& test : tests) {
		DEBUG(test.second);
		QCOMPARE(test.first.autoTickCount(), test.second);
	}
}

///////////// Performance ////////////////////////////////
/*
void ParserTest::testPerformance1() {
	const int N = 1e5;
	
	QBENCHMARK {
		for (int i = 0; i < N; i++) {
			const double x = i/100.;
			assign_symbol("x", i/100.);
			QCOMPARE(parse("x+1.", "C"), x+1.);
		}
	}
}

void ParserTest::testPerformance2() {
	const int N = 1e5;
	
	QBENCHMARK {
		for (int i = 0; i < N; i++) {
			assign_symbol("alpha", i/100.);
			QCOMPARE(parse("sin(alpha)^2 + cos(alpha)^2", "C"), 1.);
		}
	}
}*/

QTEST_MAIN(RangeTest)