DGtal 1.3.0
Loading...
Searching...
No Matches
testTableReader.cpp
Go to the documentation of this file.
1
31#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
40using namespace std;
41using namespace DGtal;
42
43
45// Functions for testing class TableReader.
47
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;
68
69 trace.beginBlock( "Testing reading all numbers from each lines ..." );
70
71 std::vector<vector<unsigned int>> vectLineIntegers =
73 for ( unsigned int k = 0; k < vectLineIntegers.size(); k++ )
74 {
75 for ( unsigned int l = 0; l < vectLineIntegers.at( k ).size(); l++ )
76 {
77 trace.info() << " integer: " << vectLineIntegers.at( k ).at( l ) << " ";
78 }
79 trace.info() << endl;
80 }
81
82 nbok += ( vectLineIntegers.at( 0 ).at( 0 ) == 1 &&
83 vectLineIntegers.at( 2 ).at( 2 ) == 9 &&
84 vectLineIntegers.at( 3 ).at( 2 ) == 1 )
85 ? 1
86 : 0;
87 nb++;
88 trace.info() << "(" << nbok << "/" << nb << ") " << std::endl;
90
91 trace.beginBlock ( "Testing reading string ..." );
92
93 vector<std::string> vectStrings = TableReader<std::string>::getColumnElementsFromFile(filename, 2);
94 for(unsigned int k=0;k < vectStrings.size(); k++){
95 trace.info() << " string: "<< vectStrings.at(k)<< endl;
96 }
97 nbok += (vectStrings.at(0)=="3" && vectStrings.at(1)=="4" && vectStrings.at(2)=="9"
98 && vectStrings.at(3)=="1") ? 1 : 0;
99 nb++;
100 trace.info() << "(" << nbok << "/" << nb << ") "<< std::endl;
101 trace.endBlock();
102
103 return nbok == nb;
104}
105
107// Standard services - public :
108
109int main( int argc, char** argv )
110{
111 trace.beginBlock ( "Testing class TableReader" );
112 trace.info() << "Args:";
113 for ( int i = 0; i < argc; ++i )
114 trace.info() << " " << argv[ i ];
115 trace.info() << endl;
116
117
118 bool res = testNumberReader(); // && ... other tests
119 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
120 trace.endBlock();
121 return res ? 0 : 1;
122}
123// //
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
static std::vector< TQuantity > getColumnElementsFromFile(const std::string &aFilename, unsigned int aPosition)
static std::vector< std::vector< TQuantity > > getLinesElementsFromFile(const std::string &aFilename)
int main()
Definition: testBits.cpp:56
bool testNumberReader()