Mercurial > hg > svcore
changeset 1525:a92e94215863
Various CSV format tests
author | Chris Cannam |
---|---|
date | Fri, 14 Sep 2018 14:47:46 +0100 (2018-09-14) |
parents | 64ef24ebb19c |
children | 8988b27ebf38 |
files | data/fileio/CSVFormat.cpp data/fileio/test/CSVFormatTest.h data/fileio/test/csv/model-type-1d-samples.csv data/fileio/test/csv/model-type-1d-seconds.csv data/fileio/test/csv/model-type-2d-duration-samples.csv data/fileio/test/csv/model-type-2d-duration-seconds.csv data/fileio/test/csv/model-type-2d-endtime-samples.csv data/fileio/test/csv/model-type-2d-endtime-seconds.csv data/fileio/test/csv/model-type-2d-implicit.csv data/fileio/test/csv/model-type-2d-samples.csv data/fileio/test/csv/model-type-2d-seconds.csv data/fileio/test/csv/model-type-3d-implicit.csv data/fileio/test/csv/model-type-3d-samples.csv data/fileio/test/csv/model-type-3d-seconds.csv |
diffstat | 14 files changed, 221 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/data/fileio/CSVFormat.cpp Fri Sep 14 09:25:17 2018 +0100 +++ b/data/fileio/CSVFormat.cpp Fri Sep 14 14:47:46 2018 +0100 @@ -249,6 +249,7 @@ m_timeUnits = CSVFormat::TimeWindows; int timingColumnCount = 0; + bool haveDurationOrEndTime = false; SVDEBUG << "Estimated column qualities overall: "; for (int i = 0; i < m_columnCount; ++i) { @@ -310,6 +311,7 @@ if (timingColumnCount == 2 && m_timingType == ExplicitTiming) { purpose = ColumnEndTime; + haveDurationOrEndTime = true; } } } @@ -353,15 +355,17 @@ if (m_columnQualities[timecol] & ColumnIncreasing) { // This shouldn't happen; should have been settled above m_columnPurposes[timecol] = ColumnEndTime; + haveDurationOrEndTime = true; } else { m_columnPurposes[timecol] = ColumnDuration; + haveDurationOrEndTime = true; } --valueCount; } } } - if (timingColumnCount > 1) { + if (timingColumnCount > 1 || haveDurationOrEndTime) { m_modelType = TwoDimensionalModelWithDuration; } else { if (valueCount == 0) {
--- a/data/fileio/test/CSVFormatTest.h Fri Sep 14 09:25:17 2018 +0100 +++ b/data/fileio/test/CSVFormatTest.h Fri Sep 14 14:47:46 2018 +0100 @@ -125,6 +125,152 @@ CSVFormat::ColumnNearEmpty); QCOMPARE(q, expected); } + + void modelType1DSamples() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-samples.csv"))); + QCOMPARE(f.getColumnCount(), 1); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel); + } + + void modelType1DSeconds() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-1d-seconds.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnLabel); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::OneDimensionalModel); + } + + void modelType2DSamples() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-samples.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel); + } + + void modelType2DSeconds() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-seconds.csv"))); + QCOMPARE(f.getColumnCount(), 2); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModel); + } + + void modelType2DImplicit() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-implicit.csv"))); + QCOMPARE(f.getColumnCount(), 1); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming); + } + + void modelType2DEndTimeSamples() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-samples.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + + void modelType2DEndTimeSeconds() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-endtime-seconds.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnEndTime); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + + void modelType2DDurationSamples() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-samples.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + + void modelType2DDurationSeconds() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-2d-duration-seconds.csv"))); + QCOMPARE(f.getColumnCount(), 3); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnDuration); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::TwoDimensionalModelWithDuration); + } + + void modelType3DSamples() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-samples.csv"))); + QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeAudioFrames); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + + void modelType3DSeconds() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-seconds.csv"))); + QCOMPARE(f.getColumnCount(), 7); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnStartTime); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(6), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ExplicitTiming); + QCOMPARE(f.getTimeUnits(), CSVFormat::TimeSeconds); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + + void modelType3DImplicit() { + CSVFormat f; + QVERIFY(f.guessFormatFor(csvDir.filePath("model-type-3d-implicit.csv"))); + QCOMPARE(f.getColumnCount(), 6); + QCOMPARE(f.getColumnPurpose(0), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(1), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(2), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(3), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(4), CSVFormat::ColumnValue); + QCOMPARE(f.getColumnPurpose(5), CSVFormat::ColumnValue); + QCOMPARE(f.getTimingType(), CSVFormat::ImplicitTiming); + QCOMPARE(f.getModelType(), CSVFormat::ThreeDimensionalModel); + } + }; #endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-1d-samples.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +45678 +123239 +320130 +452103 +620301
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-1d-seconds.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +3.2 First thing +4.4 Second thing +5.5 Third thing +6.3 Fourth thing +7.8 Fifth thing
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-duration-samples.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,9 @@ +# Here we see something that looks like time - value - value, but the +# time column is integral and so is exactly one of the value columns, +# so we deduce that that one is actually duration. We can only do this +# if the values are non-integral +45678,123,4 +123239,4214,4.2 +320130,12312,0.4 +452103,4123,3.8 +620301,987654,-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-duration-seconds.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,8 @@ +# There are only very limited circumstances in which we deduce that we +# have a time+duration 2d model with units of seconds - basically only +# when the values column is entirely integer values +1.1,4,620 +2.2,4.2,880 +3.3,0.4,440 +4.4,3.8,213 +5.5,-2.3,123
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-endtime-samples.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +45678,49000,4 +123239,330123,4.2 +320130,350000,0.4 +452103,540325,3.8 +620301,850000,-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-endtime-seconds.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +1.1,1.4,4 +2.2,3.1,4.2 +3.3,4.5,0.4 +4.4,4.6,3.8 +5.5,5.51,-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-implicit.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +4 +4.2 +0.4 +3.8 +-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-samples.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +45678,4 +123239,4.2 +320130,0.4 +452103,3.8 +620301,-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-2d-seconds.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,5 @@ +1.1,4 +2.2,4.2 +3.3,0.4 +4.4,3.8 +5.5,-2.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-3d-implicit.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,6 @@ +143.0,2.0,-1.3,0.0,0.0,1.0 +0.2,0.1,-3.0,0.0,0.1,0.143 +0.143,0.2,-3.1,0.0,0.0,0.1 +2.0,1.0,-0.3,0.0,1.0,143.0 +0.0,0.0,0.1,0.143,0.2,-3.1 +0.0,1.0,143.0,2.0,1.0,-0.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-3d-samples.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,6 @@ +22050,143.0,2.0,-1.3,0.0,0.0,1.0 +44100,0.2,0.1,-3.0,0.0,0.1,0.143 +66150,0.143,0.2,-3.1,0.0,0.0,0.1 +88200,2.0,1.0,-0.3,0.0,1.0,143.0 +110250,0.0,0.0,0.1,0.143,0.2,-3.1 +132300,0.0,1.0,143.0,2.0,1.0,-0.3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/data/fileio/test/csv/model-type-3d-seconds.csv Fri Sep 14 14:47:46 2018 +0100 @@ -0,0 +1,6 @@ +1.1,143.0,2.0,-1.3,0.0,0.0,1.0 +2.2,0.2,0.1,-3.0,0.0,0.1,0.143 +3.3,0.143,0.2,-3.1,0.0,0.0,0.1 +4.4,2.0,1.0,-0.3,0.0,1.0,143.0 +5.5,0.0,0.0,0.1,0.143,0.2,-3.1 +6.6,0.0,1.0,143.0,2.0,1.0,-0.3