comparison data/fileio/test/CSVReaderTest.h @ 1873:1d44fdc8196c csv-import-headers

Extend tests to include testing (at least some of) the actual data as well as the layout
author Chris Cannam
date Thu, 18 Jun 2020 13:42:48 +0100
parents 566476eeeb80
children f49afb5b9eac
comparison
equal deleted inserted replaced
1872:566476eeeb80 1873:1d44fdc8196c
75 Model *model = nullptr; 75 Model *model = nullptr;
76 loadFrom("model-type-1d-samples.csv", model); 76 loadFrom("model-type-1d-samples.csv", model);
77 auto actual = qobject_cast<SparseOneDimensionalModel *>(model); 77 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
78 QVERIFY(actual); 78 QVERIFY(actual);
79 QCOMPARE(actual->getAllEvents().size(), 5); 79 QCOMPARE(actual->getAllEvents().size(), 5);
80 //!!! + the actual contents 80 vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
81 for (int i = 0; in_range_for(expected, i); ++i) {
82 QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
83 }
81 delete model; 84 delete model;
82 } 85 }
83 86
84 void modelType1DSamplesWithHeader() { 87 void modelType1DSamplesWithHeader() {
85 Model *model = nullptr; 88 Model *model = nullptr;
86 loadFrom("model-type-1d-samples-header.csv", model); 89 loadFrom("model-type-1d-samples-header.csv", model);
87 auto actual = qobject_cast<SparseOneDimensionalModel *>(model); 90 auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
88 QVERIFY(actual); 91 QVERIFY(actual);
89 QCOMPARE(actual->getAllEvents().size(), 5); 92 QCOMPARE(actual->getAllEvents().size(), 5);
90 //!!! + the actual contents 93 vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
94 for (int i = 0; in_range_for(expected, i); ++i) {
95 QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
96 }
91 delete model; 97 delete model;
92 } 98 }
93 99
94 void modelType1DSeconds() { 100 void modelType1DSeconds() {
95 Model *model = nullptr; 101 Model *model = nullptr;
195 Model *model = nullptr; 201 Model *model = nullptr;
196 loadFrom("model-type-2d-implicit.csv", model); 202 loadFrom("model-type-2d-implicit.csv", model);
197 auto actual = qobject_cast<SparseTimeValueModel *>(model); 203 auto actual = qobject_cast<SparseTimeValueModel *>(model);
198 QVERIFY(actual); 204 QVERIFY(actual);
199 QCOMPARE(actual->getAllEvents().size(), 5); 205 QCOMPARE(actual->getAllEvents().size(), 5);
206 vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
207 vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
208 vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
209 for (int i = 0; in_range_for(expectedFrames, i); ++i) {
210 QCOMPARE(actual->getAllEvents()[i],
211 Event(expectedFrames[i],
212 expectedValues[i],
213 expectedLabels[i]));
214 }
200 delete model; 215 delete model;
201 } 216 }
202 217
203 void modelType2DImplicitWithHeader() { 218 void modelType2DImplicitWithHeader() {
204 Model *model = nullptr; 219 Model *model = nullptr;
205 loadFrom("model-type-2d-implicit-header.csv", model); 220 loadFrom("model-type-2d-implicit-header.csv", model);
206 auto actual = qobject_cast<SparseTimeValueModel *>(model); 221 auto actual = qobject_cast<SparseTimeValueModel *>(model);
207 QVERIFY(actual); 222 QVERIFY(actual);
208 QCOMPARE(actual->getAllEvents().size(), 5); 223 QCOMPARE(actual->getAllEvents().size(), 5);
224 vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
225 vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
226 vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
227 for (int i = 0; in_range_for(expectedFrames, i); ++i) {
228 QCOMPARE(actual->getAllEvents()[i],
229 Event(expectedFrames[i],
230 expectedValues[i],
231 expectedLabels[i]));
232 }
209 delete model; 233 delete model;
210 } 234 }
211 235
212 void modelType2DSamples() { 236 void modelType2DSamples() {
213 Model *model = nullptr; 237 Model *model = nullptr;