DGtal  0.9.2
testTableReader.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/io/readers/TableReader.h"
34 #include "DGtal/helpers/StdDefs.h"
35 
36 #include "ConfigTest.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 
43 
45 // Functions for testing class TableReader.
47 
51 bool testNumberReader()
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
55 
56  trace.beginBlock ( "Testing reading Integers ..." );
57  std::string filename = testPath + "samples/pointList1.pl";
58 
59  vector<unsigned int> vectIntegers = TableReader<unsigned int>::getColumnElementsFromFile(filename, 1);
60  for(unsigned int k=0;k < vectIntegers.size(); k++){
61  trace.info() << " integer: "<< vectIntegers.at(k)<< endl;
62  }
63  nbok += (vectIntegers.at(0)==2 && vectIntegers.at(1)==44 && vectIntegers.at(2)==23
64  && vectIntegers.at(3)==1) ? 1 : 0;
65  nb++;
66  trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
67  trace.endBlock();
68 
69 
70  trace.beginBlock ( "Testing reading string ..." );
71 
72  vector<std::string> vectStrings = TableReader<std::string>::getColumnElementsFromFile(filename, 2);
73  for(unsigned int k=0;k < vectStrings.size(); k++){
74  trace.info() << " string: "<< vectStrings.at(k)<< endl;
75  }
76  nbok += (vectStrings.at(0)=="3" && vectStrings.at(1)=="4" && vectStrings.at(2)=="9"
77  && vectStrings.at(3)=="1") ? 1 : 0;
78  nb++;
79  trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
80  trace.endBlock();
81 
82  return nbok == nb;
83 }
84 
86 // Standard services - public :
87 
88 int main( int argc, char** argv )
89 {
90  trace.beginBlock ( "Testing class TableReader" );
91  trace.info() << "Args:";
92  for ( int i = 0; i < argc; ++i )
93  trace.info() << " " << argv[ i ];
94  trace.info() << endl;
95 
96 
97  bool res = testNumberReader(); // && ... other tests
98  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
99  trace.endBlock();
100  return res ? 0 : 1;
101 }
102 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
Aim: Implements method to read a set of numbers represented in each line of a file.
Definition: TableReader.h:83
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()