[complement-svn] SF.net SVN: complement: [1798] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-12-17 14:10:43
|
Revision: 1798 http://complement.svn.sourceforge.net/complement/?rev=1798&view=rev Author: complement Date: 2007-12-17 06:10:37 -0800 (Mon, 17 Dec 2007) Log Message: ----------- dry run with indent [dependency]; libexam 0.5.0 Modified Paths: -------------- trunk/complement/explore/include/exam/logger.h trunk/complement/explore/include/exam/suite.h trunk/complement/explore/lib/exam/ChangeLog trunk/complement/explore/lib/exam/Makefile.inc trunk/complement/explore/lib/exam/logger.cc trunk/complement/explore/lib/exam/suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.cc trunk/complement/explore/lib/exam/ut/exam_test_suite.h Modified: trunk/complement/explore/include/exam/logger.h =================================================================== --- trunk/complement/explore/include/exam/logger.h 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/include/exam/logger.h 2007-12-17 14:10:37 UTC (rev 1798) @@ -32,7 +32,8 @@ enum tc_result { pass = 0, fail, - skip + skip, + dry }; struct stat @@ -70,6 +71,7 @@ virtual void tc_post() = 0; virtual void tc_break() = 0; virtual void tc( tc_result, const std::string& ) = 0; + virtual void tc( tc_result, const std::string&, int ) = 0; protected: int _flags; @@ -101,6 +103,7 @@ virtual void tc_break() { } virtual void tc( base_logger::tc_result, const std::string& ); + virtual void tc( base_logger::tc_result, const std::string&, int ); protected: std::ostream *s; @@ -123,6 +126,7 @@ virtual void tc_post(); virtual void tc_break(); virtual void tc( base_logger::tc_result, const std::string& ); + virtual void tc( base_logger::tc_result, const std::string&, int ); private: typedef std::list<xmt::timespec> time_container_t; Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/include/exam/suite.h 2007-12-17 14:10:37 UTC (rev 1798) @@ -197,6 +197,11 @@ { return girdle( 0 ); } int run( test_suite *, int count = 0 ); + int dry_girdle( test_case_type start ); + int dry_girdle() + { return dry_girdle( 0 ); } + int dry_run( test_suite *, int count = 0 ); + int flags(); int flags( int ); bool is_trace(); @@ -235,6 +240,7 @@ unsigned _iterations; void run_test_case( vertex_t v, unsigned n = 1 ); + void dry_run_test_case( vertex_t v, unsigned n, int indent ); static bool vertices_compare( weight_t, weight_t ); static int _root_func( test_suite *, int = 0 ); Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-12-17 14:10:37 UTC (rev 1798) @@ -1,3 +1,13 @@ +2007-12-17 Petr Ovtchenkov <pt...@is...> + + * logger.h, logger.cc, suite.h, suite.cc: dry run with + indent [dependency] implemented; + + * ut/exam_test_suite.cc, ut/exam_test_suite.h: test for + feature above; + + * libexam: version 0.5.0. + 2007-10-05 Petr Ovtchenkov <pt...@is...> * suite.h, suite.cc: test may throw skip_exception to signal Modified: trunk/complement/explore/lib/exam/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/Makefile.inc 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/Makefile.inc 2007-12-17 14:10:37 UTC (rev 1798) @@ -2,6 +2,6 @@ LIBNAME = exam MAJOR = 0 -MINOR = 4 +MINOR = 5 PATCH = 0 SRC_CC = logger.cc suite.cc Modified: trunk/complement/explore/lib/exam/logger.cc =================================================================== --- trunk/complement/explore/lib/exam/logger.cc 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/logger.cc 2007-12-17 14:10:37 UTC (rev 1798) @@ -92,7 +92,7 @@ return; } - static const char *m[] = { " PASS ", " FAIL ", " SKIP " }; + static const char *m[] = { " PASS ", " FAIL ", " SKIP ", " DRY " }; const char *rs = ""; switch ( r ) @@ -106,6 +106,9 @@ case skip: rs = m[2]; break; + case dry: + rs = m[3]; + break; } if ( s != 0 ) { @@ -115,6 +118,25 @@ } } +void trivial_logger::tc( base_logger::tc_result r, const std::string& name, int indent ) +{ + if ( ((_flags & silent) != 0) || ((r == pass) && ((_flags & verbose) == 0) )) { + return; + } + + if ( s != 0 ) { + while ( indent-- > 0 ) { + *s << " "; + } + } else { + while ( indent-- > 0 ) { + fprintf( f, " " ); + } + } + + tc( r, name ); +} + void trivial_time_logger::tc_pre() { tst.push_back( xmt::timespec( xmt::timespec::now ) ); @@ -162,4 +184,36 @@ trivial_logger::tc( r, name ); } +void trivial_time_logger::tc( base_logger::tc_result r, const std::string& name, int indent ) +{ + if ( r == pass ) { + // here tst.size() > 0, if test case not throw excepion + time_container_t::const_iterator a = tst.begin(); + if ( a != tst.end() ) { + unsigned n = 1; + double sum(*a); + double sum_sq = sum * sum; + ++a; + for ( ; a != tst.end(); ++a ) { + double v(*a); + sum += v; + sum_sq += v * v; + // mean = ((n + 1) * mean + static_cast<double>(*a)) / (n + 2); + ++n; + } + sum_sq -= sum * sum / n; + sum_sq = max( 0.0, sum_sq ); // clear epsilon (round error) + sum_sq /= n * n; // dispersion + sum /= n; // mean + if ( s != 0 ) { + *s << " " << sum << " " << sum_sq << " " << name << endl; + } else { + fprintf( f, " %f %f %s\n", sum, sum_sq, name.c_str() ); + } + } + } + tst.clear(); + trivial_logger::tc( r, name, indent ); +} + } //namespace exam Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/suite.cc 2007-12-17 14:10:37 UTC (rev 1798) @@ -273,5 +273,83 @@ return girdle( 0 ); } +void test_suite::dry_run_test_case( test_suite::vertex_t v, unsigned n, int indent ) +{ + try { + ++_stat.total; + while ( n-- > 0 ) { + _lock_ll.lock(); + local_logger->tc_pre(); + _lock_ll.unlock(); + // res = (*_test[v].tc)( this, 0 ); + _lock_ll.lock(); + local_logger->tc_post(); + _lock_ll.unlock(); + } + ++_stat.skipped; + scoped_lock lk( _lock_ll ); + local_logger->tc( base_logger::dry, _test[v].name, indent ); + } + catch ( skip_exception& ) { + _lock_ll.lock(); + local_logger->tc_break(); + _lock_ll.unlock(); + ++_stat.skipped; + scoped_lock lk( _lock_ll ); + local_logger->tc( base_logger::skip, _test[v].name, indent ); + } + catch ( init_exception& ) { + _lock_ll.lock(); + // local_logger->tc_break(); + local_logger->tc( base_logger::dry, _test[v].name, indent ); + _lock_ll.unlock(); + --_stat.total; + } + catch ( ... ) { + ++_stat.failed; + _test[v].state = fail; + scoped_lock lk( _lock_ll ); + local_logger->tc_break(); + local_logger->tc( base_logger::fail, _test[v].name, indent ); + } +} +int test_suite::dry_girdle( test_suite::test_case_type start ) +{ + if ( start > _count ) { + throw std::logic_error( "bad start point" ); + } + + sort( _vertices.begin(), _vertices.end(), vertices_compare ); + + vector<weight_t>::iterator from; + + _stat = base_logger::stat(); + for( vector<weight_t>::iterator i = _vertices.begin(); i != _vertices.end(); ++i ) { + if ( i->first == start ) { + from = i; + } + _test[i->first].state = 0; + } + local_logger->begin_ts(); + for( vector<weight_t>::iterator i = from; i != _vertices.end(); ++i ) { + for( std::list<edge_t>::const_iterator j = _edges.begin(); j != _edges.end(); ++j ) { + if ( j->second == i->first && _test[j->first].state != 0 ) { + _test[j->second].state = skip; + } + } + dry_run_test_case( i->first, _iterations, i->second ); + } + + local_logger->end_ts(); + local_logger->result( _stat, _suite_name ); + + return _stat.failed; +} + +int test_suite::dry_run( test_suite *, int ) +{ + return dry_girdle( 0 ); +} + } // namespace exam Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-12-17 14:10:37 UTC (rev 1798) @@ -278,6 +278,48 @@ return EXAM_RESULT; } +int EXAM_IMPL(exam_basic_test::dry) +{ + buff.str( "" ); + buff.clear(); + + exam::test_suite t( "exam self test, fail function" ); + t.set_logger( &logger ); + + test_x tx; + + exam::test_suite::test_case_type tc[2]; + exam::test_suite::test_case_type tcx[2]; + + tc[0] = t.add( &test_x::f_good, tx, "member function good" ); + tc[1] = t.add( func_good, "function good" ); + + tcx[0] = t.add( func, "function fail", tc, tc + 2 ); + t.add( &test_x::f, tx, "member function fail", tc, tc + 2 ); + tcx[1] = t.add( func_good2, "function 2 good", tc, tc + 2 ); + t.add( func_good3, "function 3 good", tcx, tcx + 2 ); // <-- problem + t.add( &test_x::f_good, tx, "member function good 2" ); + + logger.flags( exam::base_logger::verbose ); + t.dry_girdle(); + logger.flags( 0 ); + + // std::cerr << "%%%\n"; + // std::cerr << buff.str(); + // std::cerr << "%%%\n"; + // std::cerr << r10 << std::endl; + // std::cerr << "%%%\n"; + // int j = 0; + // while ( (j < buff.str().length()) && (buff.str().at(j) == r10[j]) ) { + // ++j; + // } + // std::cerr << buff.str().substr(j) << "; " << j << " " << int(buff.str().at(j)) << " " << int(r10[j]) << std::endl; + + EXAM_REQUIRE( buff.str() == r10 ); + + return EXAM_RESULT; +} + const std::string exam_basic_test::r0 = "\ *** PASS exam self test, good function (+2-0~0/2) ***\n"; @@ -347,6 +389,17 @@ SKIP function 3 good\n\ *** FAIL exam self test, fail function (+3-2~1/6) ***\n"; +const std::string exam_basic_test::r10 = "\ + DRY \n\ + DRY member function good\n\ + DRY function good\n\ + DRY member function good 2\n\ + DRY function fail\n\ + DRY member function fail\n\ + DRY function 2 good\n\ + DRY function 3 good\n\ +*** PASS exam self test, fail function (+0-0~8/8) ***\n"; + int EXAM_IMPL(exam_self_test) { exam::test_suite t( "exam self test" ); @@ -361,6 +414,7 @@ t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); t.add( &exam_basic_test::perf, exam_basic, "performance timer test", d0 ); + t.add( &exam_basic_test::dry, exam_basic, "complex multiple dependencies, dry run", d2 ); return t.girdle(); } Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.h =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-12-11 23:02:38 UTC (rev 1797) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.h 2007-12-17 14:10:37 UTC (rev 1798) @@ -31,6 +31,7 @@ int EXAM_DECL(multiple_dep); int EXAM_DECL(multiple_dep_complex); int EXAM_DECL(perf); + int EXAM_DECL(dry); private: std::stringstream buff; @@ -48,6 +49,7 @@ static const std::string r7; static const std::string r8; static const std::string r9; + static const std::string r10; }; int EXAM_DECL(exam_self_test); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |