changeset 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 48f50a4a82ea
files data/fileio/test/CSVFormatTest.h data/fileio/test/CSVReaderTest.h data/fileio/test/csv/model-type-1d-samples-header.csv data/fileio/test/csv/model-type-2d-implicit.csv
diffstat 4 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/data/fileio/test/CSVFormatTest.h	Thu Jun 18 11:55:28 2020 +0100
+++ b/data/fileio/test/CSVFormatTest.h	Thu Jun 18 13:42:48 2020 +0100
@@ -236,9 +236,10 @@
     void modelType2DImplicit() {
         CSVFormat f;
         QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-implicit.csv")));
-        QCOMPARE(f.getColumnCount(), 1);
+        QCOMPARE(f.getColumnCount(), 2);
         QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderAbsent);
         QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue);
+        QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel);
         QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming);
     }
     
@@ -248,6 +249,7 @@
         QCOMPARE(f.getColumnCount(), 2);
         QCOMPARE(f.getHeaderStatus(), CSVFormat::HeaderPresent);
         QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue);
+        QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel);
         QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming);
     }
     
--- a/data/fileio/test/CSVReaderTest.h	Thu Jun 18 11:55:28 2020 +0100
+++ b/data/fileio/test/CSVReaderTest.h	Thu Jun 18 13:42:48 2020 +0100
@@ -77,7 +77,10 @@
         auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
         QVERIFY(actual);
         QCOMPARE(actual->getAllEvents().size(), 5);
-        //!!! + the actual contents
+        vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
+        for (int i = 0; in_range_for(expected, i); ++i) {
+            QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
+        }
         delete model;
     }
 
@@ -87,7 +90,10 @@
         auto actual = qobject_cast<SparseOneDimensionalModel *>(model);
         QVERIFY(actual);
         QCOMPARE(actual->getAllEvents().size(), 5);
-        //!!! + the actual contents
+        vector<sv_frame_t> expected { 45678, 123239, 320130, 452103, 620301 };
+        for (int i = 0; in_range_for(expected, i); ++i) {
+            QCOMPARE(actual->getAllEvents()[i], Event(expected[i]));
+        }
         delete model;
     }
 
@@ -197,6 +203,15 @@
         auto actual = qobject_cast<SparseTimeValueModel *>(model);
         QVERIFY(actual);
         QCOMPARE(actual->getAllEvents().size(), 5);
+        vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
+        vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
+        vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
+        for (int i = 0; in_range_for(expectedFrames, i); ++i) {
+            QCOMPARE(actual->getAllEvents()[i],
+                     Event(expectedFrames[i],
+                           expectedValues[i],
+                           expectedLabels[i]));
+        }
         delete model;
     }
     
@@ -206,6 +221,15 @@
         auto actual = qobject_cast<SparseTimeValueModel *>(model);
         QVERIFY(actual);
         QCOMPARE(actual->getAllEvents().size(), 5);
+        vector<sv_frame_t> expectedFrames { 0, 1024, 2048, 3072, 4096 };
+        vector<float> expectedValues { 4.f, 4.2f, 0.4f, 3.8f, -2.3f };
+        vector<QString> expectedLabels { {}, {}, "A label", {}, {} };
+        for (int i = 0; in_range_for(expectedFrames, i); ++i) {
+            QCOMPARE(actual->getAllEvents()[i],
+                     Event(expectedFrames[i],
+                           expectedValues[i],
+                           expectedLabels[i]));
+        }
         delete model;
     }
     
--- a/data/fileio/test/csv/model-type-1d-samples-header.csv	Thu Jun 18 11:55:28 2020 +0100
+++ b/data/fileio/test/csv/model-type-1d-samples-header.csv	Thu Jun 18 13:42:48 2020 +0100
@@ -1,6 +1,6 @@
 FRAME,LABEL
 45678
 123239
+452103
 320130
-452103
 620301
\ No newline at end of file
--- a/data/fileio/test/csv/model-type-2d-implicit.csv	Thu Jun 18 11:55:28 2020 +0100
+++ b/data/fileio/test/csv/model-type-2d-implicit.csv	Thu Jun 18 13:42:48 2020 +0100
@@ -1,5 +1,5 @@
 4
 4.2
-0.4
+0.4,A label
 3.8
 -2.3