DGtal  0.9.3
Functions
testTableReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/io/readers/TableReader.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigTest.h"
Include dependency graph for testTableReader.cpp:

Go to the source code of this file.

Functions

bool testNumberReader ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2013/11/30

Functions for testing class NumbersReader.

This file is part of the DGtal library.

Definition in file testTableReader.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 88 of file testTableReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testNumberReader(), and DGtal::trace.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
bool testNumberReader()
double endBlock()
std::ostream & emphase()
std::ostream & info()

◆ testNumberReader()

bool testNumberReader ( )

Example of a test. To be completed.

Definition at line 51 of file testTableReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
Aim: Implements method to read a set of numbers represented in each line of a file.
Definition: TableReader.h:83
std::ostream & info()