DGtal 1.4.0
Loading...
Searching...
No Matches
testIndexedListWithBlocks.cpp File Reference
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include "DGtal/base/Common.h"
#include "DGtal/base/IndexedListWithBlocks.h"
#include "DGtal/base/Labels.h"
Include dependency graph for testIndexedListWithBlocks.cpp:

Go to the source code of this file.

Functions

template<typename Container1 , typename Container2 >
bool isEqual (Container1 &c1, Container2 &c2)
 
template<typename VContainer1 , typename LContainer2 >
void insert (VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)
 
template<typename VContainer1 , typename LContainer2 >
bool checkInsert (VContainer1 &v, LContainer2 &l, unsigned int nb)
 
template<typename VContainer1 , typename LContainer2 >
void erase (VContainer1 &c1, LContainer2 &c2, unsigned int idx)
 
template<typename VContainer1 , typename LContainer2 >
bool checkErase (VContainer1 &v, LContainer2 &l, unsigned int nb)
 
int main ()
 

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
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2012/07/02

This file is part of the DGtal library

Definition in file testIndexedListWithBlocks.cpp.

Function Documentation

◆ checkErase()

template<typename VContainer1 , typename LContainer2 >
bool checkErase ( VContainer1 & v,
LContainer2 & l,
unsigned int nb )

Definition at line 81 of file testIndexedListWithBlocks.cpp.

83{
84 for ( unsigned int i = 0; i < nb; ++i )
85 {
86 unsigned int idx = rand() % ( l.size() );
87 erase( v, l, idx );
88 }
89 return isEqual( v, l );
90}
void erase(VContainer1 &c1, LContainer2 &c2, unsigned int idx)
bool isEqual(Container1 &c1, Container2 &c2)

References erase(), and isEqual().

Referenced by main().

◆ checkInsert()

template<typename VContainer1 , typename LContainer2 >
bool checkInsert ( VContainer1 & v,
LContainer2 & l,
unsigned int nb )

Definition at line 60 of file testIndexedListWithBlocks.cpp.

62{
63 for ( unsigned int i = 0; i < nb; ++i )
64 {
65 unsigned int idx = rand() % ( l.size() + 1 );
66 double val = ( (double)rand() ) / RAND_MAX;
67 insert( v, l, idx, val );
68 }
69 return isEqual( v, l );
70}
void insert(VContainer1 &c1, LContainer2 &c2, unsigned int idx, double v)

References insert(), and isEqual().

Referenced by main().

◆ erase()

template<typename VContainer1 , typename LContainer2 >
void erase ( VContainer1 & c1,
LContainer2 & c2,
unsigned int idx )

Definition at line 73 of file testIndexedListWithBlocks.cpp.

74{
75 c1.erase( c1.begin() + idx );
76 c2.erase( idx );
77}

Referenced by checkErase().

◆ insert()

template<typename VContainer1 , typename LContainer2 >
void insert ( VContainer1 & c1,
LContainer2 & c2,
unsigned int idx,
double v )
Examples
geometry/volumes/standardDigitalPolyhedronBuilder3D.cpp.

Definition at line 52 of file testIndexedListWithBlocks.cpp.

53{
54 c1.insert( c1.begin() + idx, v );
55 c2.insert( idx, v );
56}

Referenced by checkInsert(), main(), and main().

◆ isEqual()

template<typename Container1 , typename Container2 >
bool isEqual ( Container1 & c1,
Container2 & c2 )

Definition at line 45 of file testIndexedListWithBlocks.cpp.

46{
47 return ( c1.size() == c2.size() )
48 && std::equal( c1.begin(), c1.end(), c2.begin() );
49}

Referenced by checkErase(), checkInsert(), main(), and TEST_CASE_METHOD().

◆ main()

int main ( void )

Definition at line 93 of file testIndexedListWithBlocks.cpp.

94{
95 typedef IndexedListWithBlocks<double, 2, 10> MyIndexedList;
96 BOOST_CONCEPT_ASSERT(( boost::Container< MyIndexedList > ));
99 unsigned int nb = 0;
100 unsigned int nbok = 0;
101 trace.beginBlock ( "Testing IndexedListWithBlocks" );
102 MyIndexedList l;
103 vector<double> v;
104 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
105 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
106 insert( v, l, 0, 4.5 );
107 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
108 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
109 insert( v, l, 0, 10.1 );
110 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
111 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
112 insert( v, l, 1, 3.7 );
113 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
114 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
115 insert( v, l, 2, 8.4 );
116 insert( v, l, 1, 2.1 );
117 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
118 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
119 insert( v, l, 2, -3.0 );
120 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
121 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
122 insert( v, l, (unsigned int)v.size(), -13.1 );
123 ++nb; nbok += isEqual( v, l ) ? 1 : 0;
124 std::cout << "(" << nbok << "/" << nb << ") l=" << l << std::endl;
125 ++nb; nbok += checkInsert( v, l, 10000 ) ? 1 : 0;
126 std::cout << "(" << nbok << "/" << nb << ") 10000 insertions" << std::endl;
127 ++nb; nbok += checkErase( v, l, 10000 ) ? 1 : 0;
128 std::cout << "(" << nbok << "/" << nb << ") 10000 deletions l=" << l << std::endl;
129 trace.endBlock();
130 return ( nb == nbok ) ? 0 : 1;
131}
Aim: Represents a mixed list/array structure which is useful in some context. It is essentially a lis...
void beginBlock(const std::string &keyword="")
double endBlock()
Trace trace
Definition Common.h:153
Go to http://www.sgi.com/tech/stl/Container.html.
Definition Boost.dox:104
Go to http://www.sgi.com/tech/stl/ForwardIterator.html.
Definition Boost.dox:40
bool checkInsert(VContainer1 &v, LContainer2 &l, unsigned int nb)
bool checkErase(VContainer1 &v, LContainer2 &l, unsigned int nb)

References DGtal::Trace::beginBlock(), checkErase(), checkInsert(), DGtal::Trace::endBlock(), insert(), isEqual(), and DGtal::trace.