Java iterators for C++:
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
Classes | Macros | Functions
test_iterJava.cpp File Reference

Test ==> class iterJava<>. More...

#include "iterJava.h"
#include "str2list.h"
#include "BUnit.h"
#include <cassert>
#include "Tree_BF.h"
#include "Tree_LRP.h"
#include "Tree_LPR.h"
#include "Tree_PLR.h"
#include <cmath>
#include <iostream>

Go to the source code of this file.

Classes

class  test_iterJava
 Test ==> iterJava<>. More...
 
class  Random
 C++ encapsulation of a generator as a Java iterator. More...
 

Macros

#define dim(V)   ( sizeof(V)/sizeof(*V) )
 
#define const_error
 

Functions

std::list< long > makeList_long (const char *V)
 
void const_compile_error (std::list< long > &L)
 Implementation to show that const_iterator cannot be used to erase values. More...
 
template<typename C >
bool isPalindrome (const C &CCC)
 Returns true when CCC is a palindrome. More...
 
bool palindromo (const std::list< std::string > &L)
 Regresa true si al recorrer el contenedor "L" hacia adelante se obtiene el mismo resultado que al recorrerlo hacia atrás. More...
 
void make_a_o (TL::Tree< char > &T)
 T = ( a ( b ( f g h ) c d e ( i j ( l m ( n o ) ) k ) ). More...
 
void make_0_6 (TL::Tree< char > &T)
 T = ( 0 ( 1 ( 3 4 ) 2 ( 5 6 ) ) ). More...
 
void make_A_H (TL::Tree< char > &T)
 T = ( F ( B ( A ( C E ) D ) ) G ( I ( H ) ) ). More...
 
void make_A_O (TL::Tree< char > &T)
 T = ( A ( B ( D ( H I) E ( J K ) ) C ( F ( L M ) G ( N O ) ) ) ). More...
 
void generateRandom ()
 Example usage of Java iterators as generators. More...
 
template<class Collection >
void useIterator (Collection &C)
 Example usage of the iterJava<> iterator class. More...
 
int main ()
 Test ==> main() ==> iterJava(). More...
 

Detailed Description

Test ==> class iterJava<>.

Author
Adolfo Di Mare adolf.nosp@m.o@di.nosp@m.-mare.nosp@m..com
Date
2009

Definition in file test_iterJava.cpp.

Macro Definition Documentation

#define dim (   V)    ( sizeof(V)/sizeof(*V) )
#define const_error

Function Documentation

std::list<long> makeList_long ( const char *  V)
void const_compile_error ( std::list< long > &  L)

Implementation to show that const_iterator cannot be used to erase values.

Definition at line 178 of file test_iterJava.cpp.

template<typename C >
isPalindrome ( const C &  CCC)

Returns true when CCC is a palindrome.

  • Traversing a palindrome forward yields the same secuence of values as traversing it backwards.
{{ // test::palindrome()
std::list<long> L = makeList_long( "( 1 2 3 2 1 )" );
typedef std::list<long>::const_iterator IterFwd;
typedef std::reverse_iterator<IterFwd> IterBck;
iterJava< IterFwd > itFwd( L.begin(), L.end() );
iterJava< IterBck > itBck( L.rbegin(), L.rend() );
while ( itFwd.hasNext() && itBck.hasNext() ) {
if ( itFwd.next() != itBck.next() ) {
assertTrue( "palindrome error" && false );
}
}
assertTrue( !itFwd.hasNext() && !itBck.hasNext() );
}}

template <typename C> bool isPalindrome( const C& CCC ) {{
typedef typename C::const_iterator Iter;
iterJava< Iter > itFwd, itBck;
itFwd.set(CCC);
itBck.set(CCC); itBck.setReverse();
while ( itFwd.hasNext() && itBck.hasNext() ) {
if ( itFwd.next() != itBck.next() ) {
return false;
}
}
return ( !itFwd.hasNext() && !itBck.hasNext() );
}}

{{ // test::isPalindrome()
assertFalse( isPalindrome( makeList_long( "( 1 2 3 4 5 )" ) ) );
assertTrue( isPalindrome( makeList_long( "( 1 2 3 2 1 )" ) ) );
assertTrue( isPalindrome( makeList_long( "( 1 )" ) ) );
assertTrue( isPalindrome( makeList_long( "( 1 2 1 )" ) ) );
assertTrue( isPalindrome( makeList_long( "( )" ) ) );
}}

See Also
test_iterJava::test_palindrome()
test_iterJava::test_isPalindrome()

Definition at line 257 of file test_iterJava.cpp.

bool palindromo ( const std::list< std::string > &  L)

Regresa true si al recorrer el contenedor "L" hacia adelante se obtiene el mismo resultado que al recorrerlo hacia atrás.

Un palíndromo es una palabra que se lee igual al derecho que al revés.

{{ // test::palindromo()
assertTrue( palindromo( str2list( "[ 1 2 3 2 1 ]") ) );
assertFalse( palindromo( str2list( "[ 1 2 3 2 0 ]") ) );
assertTrue( palindromo( str2list( "[ r a d a r ]") ) );
assertFalse( palindromo( str2list( "[ M A J E M ]") ) );
}}

Definition at line 351 of file test_iterJava.cpp.

void make_a_o ( TL::Tree< char > &  T)

T = ( a ( b ( f g h ) c d e ( i j ( l m ( n o ) ) k ) ).

T = a
|--b
| |--f
T = a | |--g
/|\ | +--h
/ / \ \ |--c
b c d e |--d
/|\ /|\ +--e
f g h i j k |--i
/ \ |--j
l m | |--l
/ \ | +--m
n o | |--n
| +--o
+--k

Definition at line 870 of file test_iterJava.cpp.

void make_0_6 ( TL::Tree< char > &  T)

T = ( 0 ( 1 ( 3 4 ) 2 ( 5 6 ) ) ).

T = 0
T = 0 |--1
./ \. | |--3
1 2 | +--4
./ \ / \. +--2
3 4 5 6 |--5
+--6

Definition at line 919 of file test_iterJava.cpp.

void make_A_H ( TL::Tree< char > &  T)

T = ( F ( B ( A ( C E ) D ) ) G ( I ( H ) ) ).

F
T = F |--B
./ \. | |--A
B G | | |--C
./ \ \. | | +--E
A D I | +--D
./ \ /. +--G
C E H +--I

+–H

Definition at line 955 of file test_iterJava.cpp.

void make_A_O ( TL::Tree< char > &  T)

T = ( A ( B ( D ( H I) E ( J K ) ) C ( F ( L M ) G ( N O ) ) ) ).

T = A
|--B
| |--D
T = A | | |--H
./ \. | | +--I
./ \. | +--E
./ \. | |--J
B C | +--K
./ \ / \. +--C
D E F G |--F
./ \ / \ / \ / \. | |--L
H I J K L M N O | +--M

+–G |–N +–O

Definition at line 1003 of file test_iterJava.cpp.

void generateRandom ( )

Example usage of Java iterators as generators.

Definition at line 1075 of file test_iterJava.cpp.

template<class Collection >
void useIterator ( Collection &  C)

Example usage of the iterJava<> iterator class.

Definition at line 1089 of file test_iterJava.cpp.

int main ( )

Test ==> main() ==> iterJava().

Definition at line 1106 of file test_iterJava.cpp.