49 return wasSuccessful();
55 const char blank =
' ';
75 std::list<long> Li, Lj;
80 for (
int j=1; j<=5; ++j ) {
83 assertTrue( Li == Lj );
97 assertTrue( Li == Lj );
101 assertTrue( Li == Lj );
104 Lj =
makeList_long(
"| [1] [22] [333] [4444] [5555] |... ignore");
105 assertTrue( Li == Lj );
108 Lj =
makeList_long(
"( [1] [22] [333] [4444] [5555] )etc ...");
109 assertTrue( Li == Lj );
117 std::list<long> Li, Lj;
120 assertTrue( Li == Lj );
122 Li =
makeList_long(
"( ++101 --202 +-+-303 -+-+404 -+-+--505 )" );
123 assertTrue( Li == Lj );
133 std::list<long> Li, Lj;
136 print_list(
"(1 , - + 22, -333, - 4444, --5555)" );
138 print_list(
"( ++101 --202 +-+-303 -+-+404 -+-+--505 )" );
142 Lj =
makeList_long(
"| [1] [-] [+] [22] [-333] [-] [4444] [--5555] | ==> (#8)");
143 assertTrue( Li == Lj );
146 Lj =
makeList_long(
"| [1] [0] [0] [22] [-333] [0] [4444] [5555] | ==> (#8)" );
147 assertTrue(
makeList_long(
" 1 0 0 22 -333 0 4444 5555 ") == Lj );
148 assertTrue( Li == Lj );
150 Li =
makeList_long(
"( ++101 --202 +-+-303 -+-+404 -+-+--505 )" );
151 Lj =
makeList_long(
"| [++101] [--202] [+-+-303] [-+-+404] [-+-+--505] | ==> (#5)");
152 assertTrue( Li == Lj );
156 std::list<long> Li, Lj;
158 for (
int j=101; j<=505; j+=101 ) {
161 assertTrue( Li == Lj );
162 Li =
makeList_long(
"( ++101 --202 +-+-303 -+-+404 -+-+--505 )" );
164 assertTrue( Li == Lj );
175 assertTrue( Li == Lj );
178 assertTrue( Li == Lj );
186 std::list<int> Li, Lj;
187 Li =
intlist(
"()" ); assertTrue( Li.empty() );
188 Li =
intlist(
" ( ) " ); assertTrue( Li.empty() );
191 for (
int j=1; j<=5; ++j ) {
194 assertTrue( Li == Lj );
197 assertTrue(
intlist(
"( ... )" ).size() == 1 );
203 assertTrue(
intlist(
"( 1 2 3 4 5 )" ) ==
intlist(
"(1,2,3,4,5)" ) );
204 assertTrue(
intlist(
"{ 1,2,3,4,5 }" ) ==
intlist(
"[1 2 3 4 5]" ) );
206 Li =
intlist(
"( 1,22,333,4444,5555 )" );
207 Lj =
intlist(
"(1,22,333,4444,5555)" );
208 assertTrue( Li == Lj );
210 Li =
intlist(
"(1 , - + 22, -333, - 4444, --5555)" );
211 Lj =
intlist(
"(1, 0,0,22, -333, 0,4444, 0)" );
212 assertTrue( Li == Lj );
214 Li =
intlist(
"( 1, 22, 333, 4444, 5555 )" );
215 Lj =
intlist(
"| [1] [22] [333] [4444] [5555] |... ignore");
216 assertTrue( Li == Lj );
218 Li =
intlist(
"( 1, 22, 333, 4444, 5555, 0, 0 )" );
219 Lj =
intlist(
"( [1] [22] [333] [4444] [5555] )etc ...");
220 assertTrue( Li == Lj );
227 std::list<double> Li, Lj;
228 Li =
doublelist(
"()" ); assertTrue( Li.empty() );
229 Li =
doublelist(
" ( ) " ); assertTrue( Li.empty() );
232 for (
double j=1; j<=5; ++j ) {
235 assertTrue( Li == Lj );
238 assertTrue(
doublelist(
"( ... )" ).size() == 1 );
249 assertTrue( Li == Lj );
251 Li =
doublelist(
"(1 , - + 22, -333, - 4444, --5555)" );
252 Lj =
doublelist(
"(1, 0,0,22, -333, 0,4444, 0)" );
253 assertTrue( Li == Lj );
255 Li =
doublelist(
"( 1, 22, 333, 4444, 5555 )" );
256 Lj =
doublelist(
"| [1] [22] [333] [4444] [5555] |... ignore");
257 assertTrue( Li == Lj );
259 Li =
doublelist(
"( 1, 22, 333, 4444, 5555, 0, 0 )" );
260 Lj =
doublelist(
"( [1] [22] [333] [4444] [5555] )etc ...");
261 assertTrue( Li == Lj );
268 std::list<std::string> Li,Lj,Lk,Ll;
269 str2list( Li ,
"( 1 22 333 4444 5555 )" );
270 str2list( Lj ,
"< 1,22,333,4444,5555 > | del " );
271 str2list( Lk ,
"{ 1 22 333 4444 5555 } | del " );
272 str2list( Ll ,
"[ 1.22.333.4444.5555 ] | del " );
273 std::list<std::string> :: const_iterator itI,itJ,itK,itL;
274 itI = Li.begin(); itJ = Lj.begin(); itK = Lk.begin(); itL = Ll.begin();
275 assertTrue( *itI ==
"1" ); assertTrue( *itI++ == *itJ++ );
276 assertTrue( *itI ==
"22" ); assertTrue( *itI++ == *itJ++ );
277 assertTrue( *itI ==
"333" ); assertTrue( *itI++ == *itJ++ );
278 assertTrue( *itI ==
"4444" ); assertTrue( *itI++ == *itJ++ );
279 assertTrue( *itI ==
"5555" ); assertTrue( *itI++ == *itJ++ );
280 assertTrue( 5 == Li.size() ); assertTrue( 5 == Lj.size() );
282 assertTrue( Li == Lj && Lj == Lk && ((Lk != Ll)) );
283 assertTrue( *itL ==
"1.22.333.4444.5555" );
284 assertTrue( 1 == Ll.size() && Ll.size() < 2 );
293 std::list<char> Lcon,Lsin;
294 Lcon =
charlist(
" { 'a' ' ' 'c' '4' '\'' '.' } " );
295 Lsin =
charlist(
" ( a ' ' c 4 ''' . ) " );
297 assertTrue( Lcon == Lsin );
298 assertTrue( Lcon.size() == 6 );
300 std::list<char>::const_iterator it;
302 for (
unsigned i=0; i<Lcon.size()-1; ++i ) { ++it; }
303 assertTrue( *it ==
'.' );
305 assertTrue( *it ==
'\'' );
308 std::list<char> Lcon,Lsin;
309 Lcon =
charlist(
" { 'a' ' ' 'c' '4' '\'' '.' } " );
310 Lsin =
charlist(
" ( a ' ' c 4 ''' . ) " );
314 std::copy( Lcon.begin(), Lcon.end(), std::ostream_iterator<char> (std::cout,
",") );
323 assertTrue(
str2list(
"").empty() &&
"list<>.empty() !!!" );
326 assertTrue(
str2list(
"{}").size() == 0 );
334 assertTrue(
str2list(
" |a| etc... ").size() == 1 );
344 assertTrue(
str2list(
"(0,1,22)").size() == 3 );
347 assertTrue(
str2list(
"( 1 2 3 4 5 )").size() == 5 );
356 assertTrue(
str2list(
"[1] [2] [3] [4] [5]") ==
str2list(
"| 1 2 3 4 5 | #5") );
357 assertTrue(
str2list(
"{ [1] [2] [3] [4] [5] }") ==
str2list(
"| 1 2 3 4 5 | #5") );
368 assertTrue(
str2list(
"(1,0,0,22,-333,0)") ==
str2list(
"| 1 0 0 22 -333 0 | #6") );
369 assertTrue(
str2list(
"(1 , - - 22, -333, - )") ==
str2list(
"| 1 - - 22 -333 - | #6") );
370 assertTrue(
str2list(
"( 0, 4444, 5555 )") ==
str2list(
"| 0 4444 5555 | #3") );
371 assertTrue(
str2list(
"( - 4444, --5555)") ==
str2list(
"| - 4444 --5555 | #3") );
386 assertTrue(
str2list(
"(1,-,-,22,-333,-)" ) ==
str2list(
"(1 , - - 22, -333, - )" ) );
387 assertTrue(
str2list(
"( 0, 4444, 5555 )" ) ==
str2list(
"( 0 4444, 5555)" ) );
393 assertTrue(
str2list (
"(5, 7, 89, 65 100)" ) ==
str2list (
"(5 7 89 65 100)" ) );
399 assertTrue(
str2list (
"(---6, 78, 98)" ) ==
str2list (
"[ ---6 78 98 ]" ) );
400 assertTrue(
str2list (
"( 4 33 758)" ) ==
str2list (
"| 4 33 758 | ..!" ) );
401 assertTrue(
str2list (
"(-4, 44, - --,-7)" ) ==
str2list (
"(-4 44 - -- -7)" ) );
410 void print(
const char* name, MAT & M ) {
411 std::cout << std::endl << name
412 <<
'[' << M.rows() <<
',' << M.cols() <<
']'
414 for (
unsigned i=0; i < M.rows(); ++i) {
415 for (
unsigned j=0; j < M.cols(); ++j) {
416 std::cout <<
" " << std::setw(6) << M(i,j);
418 std::cout << std::endl;
423 void print(
const std::list< std::string >& L ) {
424 std::list< std::string >::const_iterator it;
425 for ( it= L.begin(); it!=L.end(); ++it ) {
426 std::cout <<
" [" << (*it) <<
']';
428 std::cout << std::endl;
433 std::list< std::string > L;
437 std::cout <<
'\"'<< str <<
"\"\n";
438 std::list< std::string >::const_iterator it;
439 for ( it= L.begin(); it!=L.end(); ++it ) {
440 std::cout <<
" [" << (*it) <<
']';
442 std::cout <<
" ==> (#" << L.size() <<
")" << std::endl << std::endl;
445 std::cout <<
"assertTrue( str2list(\"" << str <<
"\") == str2list(\"|";
446 std::list< std::string >::const_iterator it;
447 for ( it= L.begin(); it!=L.end(); ++it ) {
448 std::cout <<
" " << (*it);
450 std::cout <<
" | #" << L.size() <<
"\") );" << std::endl << std::endl;
459 template <
class atype,
unsigned Nrows,
unsigned Ncols>
461 for (
unsigned i=0; i < Nrows; ++i) {
462 for (
unsigned j=0; j < Ncols; ++j) {
463 std::cout << std::setw(w) << MATRIX[i][j];
465 std:: cout << std::endl;
470 template <
class atype,
unsigned Nrows,
unsigned Ncols>
471 void setValue( atype MATRIX[Nrows][Ncols] , atype val ) {
472 for (
unsigned i=0; i < Nrows; ++i) {
473 for (
unsigned j=0; j < Ncols; ++j) {
480 template <
class atype,
unsigned Nrows,
unsigned Ncols>
482 setValue<atype,Nrows,Ncols>( MATRIX, atype(0) );
487 template <
class atype,
unsigned Nrows,
unsigned Ncols>
490 for (
unsigned i=0; i < Nrows; ++i) {
491 for (
unsigned j=0; j < Ncols; ++j) {
492 MATRIX[i][j] = atype( k++ );
536 intmatrix<4,5>( M ,
" | 1 // 3 4 5 | "
538 " | 11 12 13 .. 15 | "
539 " | 16 17 // 19 20 | " );
541 assertTrue( M[0][0] == 1 ); assertTrue( M[2][1] == 12 );
542 assertTrue( M[2][3] == 0 ); assertTrue( M[1][0] == 0 );
545 for (
size_t i=0; i<4; ++i ) {
546 for (
size_t j=0; j<5; ++j ) {
547 assertTrue( M[i][j]==k++ || M[i][j]==0 );
552 int M[3][3]; setZero<int,3,3>( M );
553 intmatrix<3,3>( M ,
" | 1 2 3 4 5 | "
555 " | 11 12 13 14 15 | "
556 " | 16 17 18 19 20 | " );
558 assertTrue( M[2][1] == 12 );
560 for (
size_t i=0; i<3; ++i ) {
561 for (
size_t j=0; j<3; ++j ) {
563 std::cout << k <<
"== k != M[" << i <<
"][" << j
564 <<
"] == " << M[i][j] << std::endl;
566 assertTrue(M[i][j]==k++ );
572 int M[7][8]; setZero<int,7,8>( M );
573 intmatrix<7,8>( M ,
" | 1 // 3 4 5 | "
575 " | 11 12 13 .. 15 | "
576 " | 16 17 // 19 20 | " );
578 assertTrue( M[2][1] == 12 );
580 for (
size_t i=0; i<4; ++i ) {
581 for (
size_t j=0; j<5; ++j ) {
582 assertTrue( M[i][j]==k++ || M[i][j]==0 );
587 int M[8][7]; setZero<int,8,7>( M );
588 intmatrix<8,7>( M ,
" | 1 : : : : | "
593 assertTrue( M[3][3] == 4 );
595 for (
size_t i=0; i<8; ++i ) {
596 for (
size_t j=0; j<7; ++j ) {
598 assertTrue( M[i][j]==k++ );
601 assertTrue( M[i][j]==0 );
607 int M[8][7]; setZero<int,8,7>( M );
608 intmatrix<8,7>( M ,
" | 1 | "
613 assertTrue( M[1][1] == 2 );
615 for (
size_t i=0; i<8; ++i ) {
616 for (
size_t j=0; j<7; ++j ) {
618 assertTrue( M[i][j]==k++ );
621 assertTrue( M[i][j]==0 );
631 std::list< std::list<std::string> > M;
636 std::list< std::list<std::string> > :: const_iterator itL = M.begin();
637 const std::list<std::string> & L0 = *itL; itL++;
638 const std::list<std::string> & L1 = *itL; itL++;
639 const std::list<std::string> & L2 = *itL; itL++;
640 const std::list<std::string> & L3 = *itL; itL++;
641 assertTrue( itL==M.end() && M.size() == 4 && sz == L3.size() );
643 assertTrue( L0 ==
str2list(
" ( 99 ) " ) );
644 assertTrue( L1 ==
str2list(
" [ . 2 , , : ] " ) );
645 assertTrue( L2 ==
str2list(
" < . . 3 , . > " ) );
646 assertTrue( L3 ==
str2list(
" { a b c 4 . } " ) );
648 assertTrue( L0.size() == 1 && L0.back() ==
"99" );
649 assertTrue( L1.size() == 3 && L1.back() ==
":" );
650 assertTrue( L2.size() == 4 && L2.front() ==
"." );
651 assertTrue( L3.size() == 5 && L3.front() ==
"a" );
653 assertTrue( L0 ==
str2list(
"(99)" ) );
654 assertTrue( L1 ==
str2list(
"(. 2 :)" ) );
655 assertTrue( L2 ==
str2list(
"(. . 3 .)" ) );
656 assertTrue( L3 ==
str2list(
"( a b c 4 .)" ) );
659 std::list< std::list<std::string> > M;
664 assertTrue( ! M.back().empty() && M.size() == 4 && sz == 5 );
666 assertTrue( ! M.back().empty() && M.size() == 3 );
669 std::list< std::list<std::string> > M;
674 assertTrue( ! M.back().empty() && M.size() == 4 && sz == 1 );
677 std::list< std::list<std::string> > M;
679 assertTrue( ! M.back().empty() && M.size() == 4 && sz == 1 );
682 std::list< std::list<std::string> > M;
684 assertTrue( ! M.back().empty() && M.size() == 4 && sz == 1 );
687 std::list< std::list<std::string> > M;
689 assertTrue( ! M.back().empty() && M.size() == 4 && sz == 2 );
697 longmatrix<4,5>( M ,
" | 1 // 3 4 5 | "
699 " | 11 12 13 .. 15 | "
700 " | 16 17 // 19 20 | " );
702 assertTrue( M[0][0] == 1 ); assertTrue( M[2][1] == 12 );
703 assertTrue( M[0][1] == 0 ); assertTrue( M[3][2] == 0 );
706 for (
size_t i=0; i<4; ++i ) {
707 for (
size_t j=0; j<5; ++j ) {
708 assertTrue( M[i][j]==k++ || M[i][j]==0 );
714 longmatrix<4,5>( M,
" | 1 2 3 4 5 | "
716 " | 11 12 13 14 15 | "
717 " | 16 17 18 19 20 | " );
719 for (
int i=0; i<4; ++i ) {
720 for (
int j=0; j<5; ++j ) {
721 if (
false) { M[2][3] = -1; }
723 fail = TestCase::toString( M[i][j] ) +
" == M";
724 fail +=
'[' + TestCase::toString(i) +
']';
725 fail +=
'[' + TestCase::toString(j) +
']' +
" != ";
726 fail += TestCase::toString(n);
727 assertTrue_Msg( fail , M[i][j] == n );
740 doublematrix<4,5>( M ,
" | 10. /// 30 40. 5.e1 | "
741 " | . 70. 80 90. 100. | "
742 " | 110 120 130 .. 150. | "
743 " | 160 170 /// 190 2.e2 | " );
744 assertTrue( M[2][1] == 120.0 );
745 assertTrue( M[1][0] == 0.0 && M[2][3] == 0.0 );
747 for (
size_t i=0; i<4; ++i ) {
748 for (
size_t j=0; j<5; ++j ) {
749 assertTrue( M[i][j]==k || M[i][j]==0 );
755 double M[4][3]; setValue<double,4,3>( M,-1 );
756 doublematrix<4,3>( M ,
" 11. 22. | 33.0 0.44e2" );
759 assertTrue( M[0][0]==11.0 && M[0][1]==22.0 ); assertTrue( M[0][2]==-1.0 );
760 assertTrue( M[1][0]==33.0 && M[1][1]==44.0 ); assertTrue( M[1][2]==-1.0 );
762 assertTrue( M[2][0]==-1.0 && M[2][1]==-1.0 ); assertTrue( M[2][2]==-1.0 );
763 assertTrue( M[3][0]==-1.0 && M[3][1]==-1.0 ); assertTrue( M[3][2]==-1.0 );
767 doublematrix<4,5>( M ,
" 11. "
771 assertTrue( M[0][0] == 11.0 );
772 assertTrue( M[1][0] == 22.0 );
773 assertTrue( M[2][0] == 33.0 );
774 assertTrue( M[3][0] == 44.0 );
778 doublematrix<6,1>( M ,
" 11e-4 "
782 assertTrue( M[0][0] == 0.0011 );
783 assertTrue( M[1][0] == 0.0022 );
784 assertTrue( M[2][0] == 0.0033 );
785 assertTrue( M[3][0] == 0.0044 );
789 longmatrix<4,5>( M ,
" | 1 | "
794 for (
int i=0; i<4; ++i ) {
795 for (
int j=0; j<1; ++j ) {
796 assertTrue( M[i][j] == k ); k++;
806 charmatrix<5,3>( A ,
" | 1 a V | "
813 charmatrix<5,3>( D ,
" | 2 c Y | "
819 for (
int j=0; j<5; ++j ) {
820 assertTrue( A[j][0] == (j)+
'1' );
822 for (
int j=0; j<5; ++j ) {
823 assertTrue( A[j][1] == (j)+
'a' );
825 for (
int j=0; j<5; ++j ) {
826 assertTrue( A[j][2] == (j)+
'V' );
839 std::cout << tester.report();
843 setZero<int,4,5>( M );
844 intmatrix<4,5>( M ,
" | 1 2 3 4 5 | " );
845 printMatrix<int,4,5>( M );
846 std::cout << std::endl;
848 setRectangularRow<int,4,5>( M );
849 intmatrix<4,5>( M ,
" | 1 | 2 | 3 | 4 | 5 | " );
850 printMatrix<int,4,5>( M );