@@ -1,142 +1,144 | |||||
1 | #include <cmath> |
|
1 | #include <cmath> | |
2 | #include <algorithm> |
|
2 | #include <algorithm> | |
3 | #include <numeric> |
|
3 | #include <numeric> | |
4 | #include <QtTest> |
|
4 | #include <QtTest> | |
5 | #include <QObject> |
|
5 | #include <QObject> | |
6 | #include <Variable/VariableController2.h> |
|
6 | #include <Variable/VariableController2.h> | |
7 | #include <Data/DateTimeRange.h> |
|
7 | #include <Data/DateTimeRange.h> | |
8 | #include <Data/IDataProvider.h> |
|
8 | #include <Data/IDataProvider.h> | |
9 | #include <Data/ScalarSeries.h> |
|
9 | #include <Data/ScalarSeries.h> | |
10 | #include <Data/DataProviderParameters.h> |
|
10 | #include <Data/DataProviderParameters.h> | |
11 | #include <Common/containers.h> |
|
11 | #include <Common/containers.h> | |
12 |
|
12 | |||
13 | #include <TestUtils/TestProviders.h> |
|
13 | #include <TestUtils/TestProviders.h> | |
14 |
|
14 | |||
15 | #define TEST_VC2_FIXTURE(slope) \ |
|
15 | #define TEST_VC2_FIXTURE(slope) \ | |
16 | VariableController2 vc; \ |
|
16 | VariableController2 vc; \ | |
17 | auto provider = std::make_shared<SimpleRange<slope>>();\ |
|
17 | auto provider = std::make_shared<SimpleRange<slope>>();\ | |
18 |
|
18 | |||
19 | #define TEST_VC2_CREATE_DEFAULT_VAR(name)\ |
|
19 | #define TEST_VC2_CREATE_DEFAULT_VAR(name)\ | |
20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ |
|
20 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00),\ | |
21 | QDate(2018,8,7),QTime(16,00));\ |
|
21 | QDate(2018,8,7),QTime(16,00));\ | |
22 | auto name = vc.createVariable("name", {}, provider, range);\ |
|
22 | auto name = vc.createVariable("name", {}, provider, range);\ | |
23 |
|
23 | |||
24 | Q_DECLARE_METATYPE(DateTimeRangeTransformation); |
|
24 | Q_DECLARE_METATYPE(DateTimeRangeTransformation); | |
25 |
|
25 | |||
26 |
|
26 | |||
27 | class TestVariableController2 : public QObject |
|
27 | class TestVariableController2 : public QObject | |
28 | { |
|
28 | { | |
29 | Q_OBJECT |
|
29 | Q_OBJECT | |
30 | public: |
|
30 | public: | |
31 | explicit TestVariableController2(QObject *parent = nullptr) : QObject(parent){} |
|
31 | explicit TestVariableController2(QObject *parent = nullptr) : QObject(parent){} | |
32 | signals: |
|
32 | signals: | |
33 |
|
33 | |||
34 | private slots: |
|
34 | private slots: | |
35 | void initTestCase(){} |
|
35 | void initTestCase(){} | |
36 | void cleanupTestCase(){} |
|
36 | void cleanupTestCase(){} | |
37 |
|
37 | |||
38 | void testCreateVariable() |
|
38 | void testCreateVariable() | |
39 | { |
|
39 | { | |
40 | TEST_VC2_FIXTURE(2); |
|
40 | TEST_VC2_FIXTURE(2); | |
41 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), |
|
41 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), | |
42 | QDate(2018,8,7),QTime(16,00)); |
|
42 | QDate(2018,8,7),QTime(16,00)); | |
43 | bool callbackCalled = false; |
|
43 | bool callbackCalled = false; | |
44 | connect(&vc,&VariableController2::variableAdded, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); |
|
44 | connect(&vc,&VariableController2::variableAdded, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); | |
45 | QVERIFY(!callbackCalled); |
|
45 | QVERIFY(!callbackCalled); | |
46 | auto var1 = vc.createVariable("var1", {}, provider, range); |
|
46 | auto var1 = vc.createVariable("var1", {}, provider, range); | |
47 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); |
|
47 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); | |
48 | QVERIFY(callbackCalled); |
|
48 | QVERIFY(callbackCalled); | |
49 | } |
|
49 | } | |
50 |
|
50 | |||
51 | void testDeleteVariable() |
|
51 | void testDeleteVariable() | |
52 | { |
|
52 | { | |
53 | TEST_VC2_FIXTURE(1); |
|
53 | TEST_VC2_FIXTURE(1); | |
54 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), |
|
54 | auto range = DateTimeRange::fromDateTime(QDate(2018,8,7),QTime(14,00), | |
55 | QDate(2018,8,7),QTime(16,00)); |
|
55 | QDate(2018,8,7),QTime(16,00)); | |
56 | bool callbackCalled = false; |
|
56 | bool callbackCalled = false; | |
57 | connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); |
|
57 | connect(&vc,&VariableController2::variableDeleted, [&callbackCalled](std::shared_ptr<Variable>){callbackCalled=true;}); | |
58 | auto var1 = vc.createVariable("var1", {}, provider, range); |
|
58 | auto var1 = vc.createVariable("var1", {}, provider, range); | |
59 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); |
|
59 | QVERIFY(SciQLop::containers::contains(vc.variables(), var1)); | |
60 | QVERIFY(!callbackCalled); |
|
60 | QVERIFY(!callbackCalled); | |
61 | vc.deleteVariable(var1); |
|
61 | vc.deleteVariable(var1); | |
62 | QVERIFY(!SciQLop::containers::contains(vc.variables(), var1)); |
|
62 | QVERIFY(!SciQLop::containers::contains(vc.variables(), var1)); | |
63 | QVERIFY(callbackCalled); |
|
63 | QVERIFY(callbackCalled); | |
64 | } |
|
64 | } | |
65 |
|
65 | |||
66 | void testGetData() |
|
66 | void testGetData() | |
67 | { |
|
67 | { | |
68 | TEST_VC2_FIXTURE(10); |
|
68 | TEST_VC2_FIXTURE(10); | |
69 | TEST_VC2_CREATE_DEFAULT_VAR(var1); |
|
69 | TEST_VC2_CREATE_DEFAULT_VAR(var1); | |
70 | check_variable_state<RangeType<10>>(var1, range); |
|
70 | check_variable_state<RangeType<10>>(var1, range); | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | void testZoom_data() |
|
73 | void testZoom_data() | |
74 | { |
|
74 | { | |
75 | QTest::addColumn<double>("zoom"); |
|
75 | QTest::addColumn<double>("zoom"); | |
76 | QTest::newRow("Zoom IN 10x") << .1; |
|
76 | QTest::newRow("Zoom IN 10x") << .1; | |
77 | QTest::newRow("Zoom OUT 10x") << 10.; |
|
77 | QTest::newRow("Zoom OUT 10x") << 10.; | |
78 | QTest::newRow("Zoom IN 1x") << 1.; |
|
78 | QTest::newRow("Zoom IN 1x") << 1.; | |
79 | } |
|
79 | } | |
80 | void testZoom() |
|
80 | void testZoom() | |
81 | { |
|
81 | { | |
82 | TEST_VC2_FIXTURE(100); |
|
82 | TEST_VC2_FIXTURE(100); | |
83 | TEST_VC2_CREATE_DEFAULT_VAR(var1); |
|
83 | TEST_VC2_CREATE_DEFAULT_VAR(var1); | |
84 | check_variable_state<RangeType<100>>(var1, range); |
|
84 | check_variable_state<RangeType<100>>(var1, range); | |
85 |
|
85 | |||
86 | QFETCH(double, zoom); |
|
86 | QFETCH(double, zoom); | |
87 | range *=zoom; |
|
87 | range *=zoom; | |
88 | vc.changeRange(var1, range); |
|
88 | vc.changeRange(var1, range); | |
89 | check_variable_state<RangeType<100>>(var1, range); |
|
89 | check_variable_state<RangeType<100>>(var1, range); | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | void testPan_data() |
|
92 | void testPan_data() | |
93 | { |
|
93 | { | |
94 | QTest::addColumn<double>("pan"); |
|
94 | QTest::addColumn<double>("pan"); | |
95 | QTest::newRow("Right 1000 seconds") << 1000.; |
|
95 | QTest::newRow("Right 1000 seconds") << 1000.; | |
96 | QTest::newRow("Left 1000 seconds") << -1000.; |
|
96 | QTest::newRow("Left 1000 seconds") << -1000.; | |
97 | QTest::newRow("Right 0.1 seconds") << .1; |
|
97 | QTest::newRow("Right 0.1 seconds") << .1; | |
98 | QTest::newRow("Left 0.1 seconds") << -.1; |
|
98 | QTest::newRow("Left 0.1 seconds") << -.1; | |
99 | } |
|
99 | } | |
100 | void testPan() |
|
100 | void testPan() | |
101 | { |
|
101 | { | |
102 | TEST_VC2_FIXTURE(10); |
|
102 | TEST_VC2_FIXTURE(10); | |
103 | TEST_VC2_CREATE_DEFAULT_VAR(var1); |
|
103 | TEST_VC2_CREATE_DEFAULT_VAR(var1); | |
104 | check_variable_state<RangeType<10>>(var1, range); |
|
104 | check_variable_state<RangeType<10>>(var1, range); | |
105 |
|
105 | |||
106 | QFETCH(double, pan); |
|
106 | QFETCH(double, pan); | |
107 |
|
107 | |||
108 | range += Seconds<double>{pan}; |
|
108 | range += Seconds<double>{pan}; | |
109 | vc.changeRange(var1, range); |
|
109 | vc.changeRange(var1, range); | |
110 | check_variable_state<RangeType<10>>(var1, range); |
|
110 | check_variable_state<RangeType<10>>(var1, range); | |
111 | } |
|
111 | } | |
112 |
|
112 | |||
113 | void testCache_data() |
|
113 | void testCache_data() | |
114 | { |
|
114 | { | |
115 | QTest::addColumn<DateTimeRangeTransformation>("transformation"); |
|
115 | QTest::addColumn<DateTimeRangeTransformation>("transformation"); | |
116 | QTest::addColumn<int>("expectedIncrement"); |
|
116 | QTest::addColumn<int>("expectedIncrement"); | |
117 | QTest::newRow("zoom in") << DateTimeRangeTransformation{0.8,Seconds<double>(0.)} << 0; |
|
117 | QTest::newRow("zoom in") << DateTimeRangeTransformation{0.8,Seconds<double>(0.)} << 0; | |
118 | QTest::newRow("tiny zoom out") << DateTimeRangeTransformation{1.01,Seconds<double>(0.)} << 0; |
|
118 | QTest::newRow("tiny zoom out") << DateTimeRangeTransformation{1.01,Seconds<double>(0.)} << 0; | |
|
119 | QTest::newRow("just under cache zoom out") << DateTimeRangeTransformation{2.0/1.1,Seconds<double>(0.)} << 0; | |||
|
120 | QTest::newRow("just over cache zoom out") << DateTimeRangeTransformation{2.001/1.1, Seconds<double>(0.)} << 2; | |||
119 | QTest::newRow("tiny pan left") << DateTimeRangeTransformation{1.,Seconds<double>(-100.)} << 0; |
|
121 | QTest::newRow("tiny pan left") << DateTimeRangeTransformation{1.,Seconds<double>(-100.)} << 0; | |
120 | QTest::newRow("tiny pan right") << DateTimeRangeTransformation{1.,Seconds<double>(100.)} << 0; |
|
122 | QTest::newRow("tiny pan right") << DateTimeRangeTransformation{1.,Seconds<double>(100.)} << 0; | |
121 | } |
|
123 | } | |
122 | void testCache() |
|
124 | void testCache() | |
123 | { |
|
125 | { | |
124 | TEST_VC2_FIXTURE(10); |
|
126 | TEST_VC2_FIXTURE(10); | |
125 | TEST_VC2_CREATE_DEFAULT_VAR(var1); |
|
127 | TEST_VC2_CREATE_DEFAULT_VAR(var1); | |
126 | check_variable_state<RangeType<10>>(var1, range); |
|
128 | check_variable_state<RangeType<10>>(var1, range); | |
127 |
|
129 | |||
128 | QFETCH(DateTimeRangeTransformation, transformation); |
|
130 | QFETCH(DateTimeRangeTransformation, transformation); | |
129 | QFETCH(int, expectedIncrement); |
|
131 | QFETCH(int, expectedIncrement); | |
130 | auto initialCount = provider->callCounter; |
|
132 | auto initialCount = provider->callCounter; | |
131 | range = range.transform(transformation); |
|
133 | range = range.transform(transformation); | |
132 | vc.changeRange(var1, range); |
|
134 | vc.changeRange(var1, range); | |
133 | check_variable_state<RangeType<10>>(var1, range); |
|
135 | check_variable_state<RangeType<10>>(var1, range); | |
134 | QCOMPARE(provider->callCounter-initialCount, expectedIncrement); |
|
136 | QCOMPARE(provider->callCounter-initialCount, expectedIncrement); | |
135 | } |
|
137 | } | |
136 | }; |
|
138 | }; | |
137 |
|
139 | |||
138 |
|
140 | |||
139 | QTEST_MAIN(TestVariableController2) |
|
141 | QTEST_MAIN(TestVariableController2) | |
140 |
|
142 | |||
141 | #include "TestVariableController2.moc" |
|
143 | #include "TestVariableController2.moc" | |
142 |
|
144 |
General Comments 0
You need to be logged in to leave comments.
Login now