DGtal  1.4.beta
testOutputIteratorAdapter.cpp File Reference
#include <iostream>
#include <map>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/base/OutputIteratorAdapter.h"
#include "DGtal/base/IteratorAdapter.h"
Include dependency graph for testOutputIteratorAdapter.cpp:

Go to the source code of this file.

Functions

bool testPairs ()
 
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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2011/09/01

Functions for testing class OutputIteratorAdapter.

This file is part of the DGtal library.

Definition in file testOutputIteratorAdapter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 130 of file testOutputIteratorAdapter.cpp.

131 {
132  trace.beginBlock ( "Testing class OutputIteratorAdapter" );
133  trace.info() << "Args:";
134  for ( int i = 0; i < argc; ++i )
135  trace.info() << " " << argv[ i ];
136  trace.info() << endl;
137 
138  bool res = testPairs()
139  ; // && ... other tests
140  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
141  trace.endBlock();
142  return res ? 0 : 1;
143 }
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:153
bool testPairs()

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

◆ testPairs()

bool testPairs ( )

Example of a test. To be completed.

Definition at line 53 of file testOutputIteratorAdapter.cpp.

54 {
55  int nb = 0;
56  int nbok = 0;
57 
58  typedef map<string,string> Map;
59  typedef pair<string,string> Pair;
60 
61  //input
62  Map m;
63  m.insert( Pair("Proudhon", "Pierre-Joseph" ) );
64  m.insert( Pair("Reclus", "Élisée" ) );
65  m.insert( Pair("Zamenhof", "Ludwik Lejzer" ) );
66 
67  typedef vector<string> Vec;
68  Vec v;
69  v.push_back( "P-J." );
70  v.push_back( "E." );
71  v.push_back( "L. L." );
72 
73  //result
74  Map m2;
75  m2.insert( Pair("Proudhon", "P-J." ) );
76  m2.insert( Pair("Reclus", "E.") );
77  m2.insert( Pair("Zamenhof", "L. L." ) );
78 
79  {//test output iterator
80  trace.beginBlock ( "OutputIteratorAdapter..." );
81 
83  BOOST_CONCEPT_ASSERT(( boost::OutputIterator<Adapter, string> ));
85 
86  Adapter a( m.begin(), f );
87 
88  copy(v.begin(), v.end(), a);
89 
90  bool flag;
91  flag = std::equal( m.begin(), m.end(), m2.begin() );
92  nbok += (flag)?1:0;
93  nb++;
94 
95  trace.info() << "(" << nbok << "/" << nb << ")" << std::endl;
96  trace.endBlock();
97  }
98 
99  {//test iterator
100  trace.beginBlock ( "IteratorAdapter..." );
101 
103 
105  BOOST_CONCEPT_ASSERT(( boost::ForwardIterator<Adapter> ));
106 
107  //writting
108  Adapter a( m.begin(), f );
109  copy(v.begin(), v.end(), a);
110  bool flag1 = std::equal( m.begin(), m.end(), m2.begin() );
111 
112  //reading
113  Adapter aBegin( m.begin(), f);
114  Adapter aEnd( m.end(), f);
115  bool flag2 = std::equal( aBegin, aEnd, v.begin() );
116 
117  nbok += (flag1 && flag2)?1:0;
118  nb++;
119 
120  trace.info() << "(" << nbok << "/" << nb << ")" << std::endl;
121  trace.endBlock();
122  }
123 
124  return (nb == nbok);
125 }
This class adapts any lvalue iterator so that operator* returns a member on the element pointed to by...
Aim: Adapts an output iterator i with a unary functor f, both given at construction,...
Aim: Define a simple unary functor that returns a reference on the first member of a pair in order to...
Go to http://www.sgi.com/tech/stl/ForwardIterator.html.
Definition: Boost.dox:40
Go to http://www.sgi.com/tech/stl/OutputIterator.html.
Definition: Boost.dox:38
std::unordered_map< Cell, CubicalCellData > Map

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

Referenced by main().