DGtal 1.3.0
Loading...
Searching...
No Matches
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"

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 109 of file testTableReader.cpp.

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

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

◆ testNumberReader()

bool testNumberReader ( )

Example of a test. To be completed.

Definition at line 51 of file testTableReader.cpp.

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}
static std::vector< TQuantity > getColumnElementsFromFile(const std::string &aFilename, unsigned int aPosition)
static std::vector< std::vector< TQuantity > > getLinesElementsFromFile(const std::string &aFilename)

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::TableReader< TQuantity >::getColumnElementsFromFile(), DGtal::TableReader< TQuantity >::getLinesElementsFromFile(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().