##// END OF EJS Templates
Unit tests (3)...
Alexandre Leroux -
r872:a3c02fe3bfd0
parent child
Show More
@@ -0,0 +1,199
1 #include "Data/SpectrogramSeries.h"
2
3 #include "DataSeriesBuilders.h"
4 #include "DataSeriesUtils.h"
5
6 #include <QObject>
7 #include <QtTest>
8
9 namespace {
10
11 // Aliases used to facilitate reading of test inputs
12 using X = DataContainer;
13 using Y = DataContainer;
14 using Values = DataContainer;
15 using Components = std::vector<DataContainer>;
16
17 } // namespace
18
19 /**
20 * @brief The TestSpectrogramSeries class defines unit tests on spectrogram series.
21 *
22 * Most of these unit tests use generic tests defined for DataSeries (@sa DataSeriesUtils)
23 */
24 class TestSpectrogramSeries : public QObject {
25 Q_OBJECT
26 private slots:
27
28 /// Tests construction of a spectrogram series
29 void testCtor_data();
30 void testCtor();
31
32 /// Tests merge of two spectrogram series
33 void testMerge_data();
34 void testMerge();
35
36 /// @todo ALX: test subdataseries
37 /// Tests get subdata of a spectrogram series
38 void testSubDataSeries_data();
39 void testSubDataSeries();
40 };
41
42 void TestSpectrogramSeries::testCtor_data()
43 {
44 // x-axis data
45 QTest::addColumn<X>("xAxisData");
46 // y-axis data
47 QTest::addColumn<Y>("yAxisData");
48 // values data
49 QTest::addColumn<Values>("valuesData");
50
51 // construction expected to be valid
52 QTest::addColumn<bool>("expectOK");
53 // expected x-axis data (when construction is valid)
54 QTest::addColumn<X>("expectedXAxisData");
55 // expected components data (when construction is valid)
56 QTest::addColumn<Components>("expectedComponentsData");
57
58 QTest::newRow(
59 "invalidData (number of values by component aren't equal to the number of x-axis data)")
60 << X{1., 2., 3., 4., 5.} << Y{1., 2., 3.} << Values{1., 2., 3.} << false << X{}
61 << Components{};
62
63 QTest::newRow("invalidData (number of components aren't equal to the number of y-axis data)")
64 << X{1., 2., 3., 4., 5.} << Y{1., 2.} // 2 y-axis data
65 << Values{1., 2., 3., 4., 5.} // 1 component
66 << false << X{} << Components{};
67
68 QTest::newRow("sortedData") << X{1., 2., 3., 4., 5.} << Y{1., 2.} // 2 y-axis data
69 << Values{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} // 2 components
70 << true << X{1., 2., 3., 4., 5.}
71 << Components{{1., 3., 5., 7., 9.}, {2., 4., 6., 8., 10.}};
72
73 QTest::newRow("unsortedData") << X{5., 4., 3., 2., 1.} << Y{1., 2.}
74 << Values{1., 2., 3., 4., 5., 6., 7., 8., 9., 10.} << true
75 << X{1., 2., 3., 4., 5.}
76 << Components{{9., 7., 5., 3., 1.}, {10., 8., 6., 4., 2.}};
77 }
78
79 void TestSpectrogramSeries::testCtor()
80 {
81 // Creates series
82 QFETCH(X, xAxisData);
83 QFETCH(Y, yAxisData);
84 QFETCH(Values, valuesData);
85 QFETCH(bool, expectOK);
86
87 if (expectOK) {
88 auto series = SpectrogramBuilder{}
89 .setX(std::move(xAxisData))
90 .setY(std::move(yAxisData))
91 .setValues(std::move(valuesData))
92 .build();
93
94 // Validates results
95 QFETCH(X, expectedXAxisData);
96 QFETCH(Components, expectedComponentsData);
97 validateRange(series->cbegin(), series->cend(), expectedXAxisData, expectedComponentsData);
98 }
99 else {
100 QVERIFY_EXCEPTION_THROWN(SpectrogramBuilder{}
101 .setX(std::move(xAxisData))
102 .setY(std::move(yAxisData))
103 .setValues(std::move(valuesData))
104 .build(),
105 std::invalid_argument);
106 }
107 }
108
109 void TestSpectrogramSeries::testMerge_data()
110 {
111 testMerge_struct<SpectrogramSeries, Components>();
112
113 QTest::newRow("sortedMerge") << SpectrogramBuilder{}
114 .setX({1., 2., 3.})
115 .setY({1., 2.})
116 .setValues({10., 11., 20., 21., 30., 31})
117 .build()
118 << SpectrogramBuilder{}
119 .setX({4., 5., 6.})
120 .setY({1., 2.})
121 .setValues({40., 41., 50., 51., 60., 61})
122 .build()
123 << DataContainer{1., 2., 3., 4., 5., 6.}
124 << Components{{10., 20., 30., 40., 50., 60.},
125 {11., 21., 31., 41., 51., 61}};
126
127 QTest::newRow(
128 "unsortedMerge (merge not made because the two data series have different y-axes)")
129 << SpectrogramBuilder{}
130 .setX({4., 5., 6.})
131 .setY({1., 2.})
132 .setValues({40., 41., 50., 51., 60., 61})
133 .build()
134 << SpectrogramBuilder{}
135 .setX({1., 2., 3.})
136 .setY({3., 4.})
137 .setValues({10., 11., 20., 21., 30., 31})
138 .build()
139 << DataContainer{4., 5., 6.} << Components{{40., 50., 60.}, {41., 51., 61}};
140
141 QTest::newRow(
142 "unsortedMerge (unsortedMerge (merge is made because the two data series have the same "
143 "y-axis)")
144 << SpectrogramBuilder{}
145 .setX({4., 5., 6.})
146 .setY({1., 2.})
147 .setValues({40., 41., 50., 51., 60., 61})
148 .build()
149 << SpectrogramBuilder{}
150 .setX({1., 2., 3.})
151 .setY({1., 2.})
152 .setValues({10., 11., 20., 21., 30., 31})
153 .build()
154 << DataContainer{1., 2., 3., 4., 5., 6.}
155 << Components{{10., 20., 30., 40., 50., 60.}, {11., 21., 31., 41., 51., 61}};
156 }
157
158 void TestSpectrogramSeries::testMerge()
159 {
160 testMerge_t<SpectrogramSeries, Components>();
161 }
162
163 void TestSpectrogramSeries::testSubDataSeries_data()
164 {
165 testSubDataSeries_struct<SpectrogramSeries, Components>();
166
167 QTest::newRow("subDataSeries (the range includes all data)")
168 << SpectrogramBuilder{}
169 .setX({1., 2., 3.})
170 .setY({1., 2.})
171 .setValues({10., 11., 20., 21., 30., 31})
172 .build()
173 << SqpRange{0., 5.} << DataContainer{1., 2., 3.}
174 << Components{{10., 20., 30.}, {11., 21., 31.}};
175
176 QTest::newRow("subDataSeries (the range includes no data)")
177 << SpectrogramBuilder{}
178 .setX({1., 2., 3.})
179 .setY({1., 2.})
180 .setValues({10., 11., 20., 21., 30., 31})
181 .build()
182 << SqpRange{4., 5.} << DataContainer{} << Components{{}, {}};
183
184 QTest::newRow("subDataSeries (the range includes some data)")
185 << SpectrogramBuilder{}
186 .setX({1., 2., 3.})
187 .setY({1., 2.})
188 .setValues({10., 11., 20., 21., 30., 31})
189 .build()
190 << SqpRange{1.1, 3} << DataContainer{2., 3.} << Components{{20., 30.}, {21., 31.}};
191 }
192
193 void TestSpectrogramSeries::testSubDataSeries()
194 {
195 testSubDataSeries_t<SpectrogramSeries, Components>();
196 }
197
198 QTEST_MAIN(TestSpectrogramSeries)
199 #include "TestSpectrogramSeries.moc"
@@ -3,6 +3,7
3 tests = [
3 tests = [
4 [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'],
4 [['Common/TestStringUtils.cpp'],'test_string_utils','StringUtils test'],
5 [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'],
5 [['Data/TestScalarSeries.cpp'],'test_scalar','ScalarSeries test'],
6 [['Data/TestSpectrogramSeries.cpp'],'test_spectrogram','SpectrogramSeries test'],
6 [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'],
7 [['Data/TestVectorSeries.cpp'],'test_vector','VectorSeries test'],
7 [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'],
8 [['Data/TestOneDimArrayData.cpp'],'test_1d','One Dim Array test'],
8 [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'],
9 [['Data/TestOptionalAxis.cpp'],'test_optional_axis','OptionalAxis test'],
General Comments 0
You need to be logged in to leave comments. Login now