25 #ifndef WREADERCSV_TEST_H
26 #define WREADERCSV_TEST_H
30 #include <cxxtest/TestSuite.h>
32 #include "../WReaderCSV.h"
47 std::string fileName = W_FIXTURE_PATH +
"CSVs/empty.csv";
48 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
50 TS_ASSERT_THROWS_EQUALS(
WReaderCSV( fileName ).read(),
52 strcmp( e.
what(),
"CSV file is empty!" ),
61 std::string fileName = W_FIXTURE_PATH +
"CSVs/onlyHeader.csv";
62 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
64 TS_ASSERT_THROWS_EQUALS(
WReaderCSV( fileName ).read(),
66 strcmp( e.
what(),
"CSV File does not contain data!" ),
76 std::string fileName = W_FIXTURE_PATH +
"CSVs/invalidColumnCount.csv";
77 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
79 TS_ASSERT_THROWS_EQUALS(
WReaderCSV( fileName ).read(),
81 strcmp( e.
what(),
"Data row count does not equal header count!" ),
90 std::string fileName = W_FIXTURE_PATH +
"CSVs/valid.csv";
91 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
97 testHeader->push_back(
99 "PDGEncoding",
"trackID",
"parentID",
"trackLocalTime",
"time",
"edep",
"stepLength",
"trackLength",
100 "posX",
"posY",
"posZ",
"localPosX",
"localPosY",
"localPosZ",
"momDirX",
"momDirY",
"momDirZ",
"baseID",
101 "level1ID",
"level2ID",
"level3ID",
"level4ID",
"layerID",
"photonID",
"nPhantomCompton",
"nCrystalCompton",
102 "nPhantomRayleigh",
"nCrystalRayleigh",
"primaryID",
"sourcePosX",
"sourcePosY",
"sourcePosZ",
"sourceID",
"eventID",
103 "runID",
"axialPos",
"rotationAngle",
"volumeID",
"processName",
"comptVolName",
"RayleighVolName"
106 testDataFirstRow->push_back(
108 "2212",
"1",
"0",
"4.20922e-09",
"4.20922e-09",
"0.0199097",
"0.0250083",
"725.314",
"-1.86984",
"4.55793",
"225.244",
"-1.86984",
109 "4.55793",
"0.0125",
"-0.00614681",
"0.0255574",
"0.999654",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"1",
"-0.154322",
110 "0.156973",
"-500",
"0",
"1",
"0",
"277.4",
"0",
"[0;1;0;3;-1;-1;-1;-1;-1;-1]",
"Transportation",
"NULL",
"NULL"
113 testDataLastRow->push_back(
115 "2212",
"1",
"0",
"5.92057e-09",
"5.92057e-09",
"0.3312",
"0.025598",
"955.947",
"14.127",
"28.6775",
"454.394",
"14.127",
"28.6775",
116 "0.0125",
"0.216802",
"0.0338896",
"0.975627",
"1",
"22",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"1",
"-0.480459",
"0.0634152",
117 "-500",
"0",
"2",
"0",
"461.8",
"0",
"[0;2;22;3;-1;-1;-1;-1;-1;-1]",
"Transportation",
"NULL",
"NULL"
122 TS_ASSERT_THROWS_NOTHING( tmpCsvReader.
read() );
124 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getHeader()->front(), testHeader->front() );
126 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->front(), testDataFirstRow->front() );
128 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->back(), testDataLastRow->front() );
136 std::string fileName = W_FIXTURE_PATH +
"CSVs/cr.csv";
137 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
142 testHeader->push_back(
144 "header1",
"header2",
"header3"
147 testDataFirstRow->push_back(
154 TS_ASSERT_THROWS_NOTHING( tmpCsvReader.
read() );
156 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getHeader()->front(), testHeader->front() );
158 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->front(), testDataFirstRow->front() );
166 std::string fileName = W_FIXTURE_PATH +
"CSVs/lf.csv";
167 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
172 testHeader->push_back(
174 "header1",
"header2",
"header3"
177 testDataFirstRow->push_back(
184 TS_ASSERT_THROWS_NOTHING( tmpCsvReader.
read() );
186 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getHeader()->front(), testHeader->front() );
188 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->front(), testDataFirstRow->front() );
196 std::string fileName = W_FIXTURE_PATH +
"CSVs/crlf.csv";
197 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
202 testHeader->push_back(
204 "header1",
"header2",
"header3"
207 testDataFirstRow->push_back(
214 TS_ASSERT_THROWS_NOTHING( tmpCsvReader.
read() );
216 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getHeader()->front(), testHeader->front() );
218 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->front(), testDataFirstRow->front() );
226 std::string fileName = W_FIXTURE_PATH +
"CSVs/emptyColumns.csv";
227 std::cout << std::endl <<
"Test loading of " << fileName <<
"." << std::endl;
232 testHeader->push_back(
234 "header1",
"header2",
"header3"
237 testDataFirstRow->push_back(
244 TS_ASSERT_THROWS_NOTHING( tmpCsvReader.
read() );
246 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getHeader()->front(), testHeader->front() );
248 TS_ASSERT_EQUALS( tmpCsvReader.
read()->getData()->front(), testDataFirstRow->front() );
std::shared_ptr< std::vector< std::vector< std::string > > > ContentSPtr
represents a pointer to the Content
std::vector< std::vector< std::string > > Content
represents a vector containing a vector of strings.
virtual const char * what() const
Returns the message string set on throw.
Test class of WReaderCSV class.
void testInvalidColumnNumber()
if a CSV file contains rows, whose column count differs from the header, a "Data row count does not e...
void testCRLFLineEnding()
check \r\n line endings
void testCRLineEnding()
check \r line endings
void testEmptyCSV()
if an empty CSV file is loaded, a "CSV file is empty!" exception should be thrown
void testLFLineEnding()
check \n line endings
void testValidCSV()
if a valid CSV file is loaded, no exception should be thrown
void testEmptyColumns()
Empty columns should not prevent the reader from reading all columns.
void testOnlyHeaderCSV()
if a CSV file only contains a header row, a "CSV File does not contain data!" exception should be thr...
Read content from a CSV file.
virtual std::shared_ptr< WDataSetCSV > read()
Read the file and create a dataset as a vector.