| 4 | #include "unittest.h" |
| 5 | |
| 6 | int main() |
| 7 | { |
| 8 | int rv = 0; |
| 9 | |
| 10 | const std::string path = unittest::TempPath(); |
| 11 | |
| 12 | try |
| 13 | { |
| 14 | const int dataRows = 5000; |
| 15 | |
| 16 | // write test file |
| 17 | { |
| 18 | std::ofstream out(path); |
| 19 | out << "Foo,Bar,Baz" << std::endl; |
| 20 | for (int i = 0; i < dataRows; i++) |
| 21 | { |
| 22 | out << i << "," << i * 2 << "," << i * 3 << std::endl; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | // read using filename, check row count |
| 27 | { |
| 28 | rapidcsv::Document doc(path); |
| 29 | unittest::ExpectEqual(size_t, doc.GetRowCount(), dataRows); |
| 30 | } |
| 31 | |
| 32 | // read via non-binary ifstream, check row count |
| 33 | { |
| 34 | std::ifstream in(path); |
| 35 | rapidcsv::Document doc(in); |
| 36 | unittest::ExpectEqual(size_t, doc.GetRowCount(), dataRows); |
| 37 | } |
| 38 | |
| 39 | // parse msft.csv using filename, sanity check certain values |
| 40 | const size_t msftDataRows = 7804; |
| 41 | const long long msftVolumeTopRow = 21705200; |
| 42 | const long long msftVolumeBottomRow = 1031788800; |
| 43 | const long long msftMinVolume = 2304000; |
| 44 | const long long msftMaxVolume = 1031788800; |
| 45 | |
| 46 | { |
| 47 | rapidcsv::Document doc("../tests/msft.csv"); |
| 48 | std::vector<float> close = doc.GetColumn<float>("Close"); |
| 49 | std::vector<long long> volume = doc.GetColumn<long long>("Volume"); |
| 50 | unittest::ExpectEqual(size_t, doc.GetRowCount(), msftDataRows); |
| 51 | unittest::ExpectEqual(size_t, close.size(), msftDataRows); |
| 52 | unittest::ExpectEqual(size_t, volume.size(), msftDataRows); |
| 53 | unittest::ExpectEqual(long long, volume.front(), msftVolumeTopRow); |
| 54 | unittest::ExpectEqual(long long, volume.back(), msftVolumeBottomRow); |
| 55 | const auto minMaxVolume = std::minmax_element(volume.begin(), volume.end()); |
| 56 | unittest::ExpectEqual(long long, *minMaxVolume.first, msftMinVolume); |
| 57 | unittest::ExpectEqual(long long, *minMaxVolume.second, msftMaxVolume); |
| 58 | } |
| 59 | |
| 60 | // parse msft.csv via non-binary ifstream, sanity check certain values |
| 61 | { |
| 62 | std::ifstream in("../tests/msft.csv"); |
| 63 | rapidcsv::Document doc(in); |
nothing calls this directly
no test coverage detected