[complement-svn] SF.net SVN: complement: [1634] trunk/complement/explore
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-07-21 05:47:40
|
Revision: 1634 http://svn.sourceforge.net/complement/?rev=1634&view=rev Author: complement Date: 2007-07-20 22:47:37 -0700 (Fri, 20 Jul 2007) Log Message: ----------- boost graph removed; libexam: version 0.2.0 Modified Paths: -------------- 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/suite.cc trunk/complement/explore/lib/exam/ut/Makefile trunk/complement/explore/lib/exam/ut/exam_test_suite.cc Modified: trunk/complement/explore/include/exam/suite.h =================================================================== --- trunk/complement/explore/include/exam/suite.h 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/include/exam/suite.h 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 09:47:24 ptr> +// -*- C++ -*- Time-stamp: <07/07/21 09:06:00 ptr> #ifndef __suite_h #define __suite_h @@ -7,19 +7,16 @@ #include <sstream> #include <map> #include <stack> -#include <boost/graph/adjacency_list.hpp> #include <string> #include <exception> +#include <stdexcept> +#include <list> +#include <vector> +#include <algorithm> #include <mt/xmt.h> #include <exam/logger.h> -enum vertex_testcase_t { vertex_testcase }; - -namespace boost { - BOOST_INSTALL_PROPERTY( vertex, testcase ); -} // namespace boost - namespace exam { class test_suite; @@ -159,16 +156,8 @@ class test_suite { private: - typedef boost::property<vertex_testcase_t,int> TestCaseProperty; - typedef boost::property<boost::vertex_color_t, boost::default_color_type, TestCaseProperty> VColorProperty; + typedef unsigned vertex_t; - typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VColorProperty > graph_t; - typedef boost::graph_traits<graph_t>::vertex_iterator vertex_iterator_t; - - typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t; - typedef boost::property_map<graph_t,boost::vertex_color_t>::type vertex_color_map_t; - typedef boost::property_map<graph_t,vertex_testcase_t>::type vertex_testcase_map_t; - public: typedef int (*func_type)( test_suite *, int ); typedef vertex_t test_case_type; @@ -194,13 +183,9 @@ int girdle( test_case_type start ); int girdle() - { return girdle( root ); } + { return girdle( 0 ); } int run( test_suite *, int count = 0 ); - void run_test_case( vertex_t v ); - void check_test_case( vertex_t u, vertex_t v ); - void clean_test_case_state( vertex_t v ); - int flags(); int flags( int ); bool is_trace(); @@ -216,9 +201,6 @@ skip = 2 }; - graph_t g; - vertex_t root; - vertex_testcase_map_t testcase; base_logger *local_logger; xmt::mutex _lock_ll; @@ -229,12 +211,20 @@ std::string name; }; + typedef std::pair<vertex_t,vertex_t> edge_t; + typedef std::pair<vertex_t,unsigned> weight_t; typedef std::map<vertex_t,test_case_collect> test_case_map_type; + vertex_t _count; + std::list<edge_t> _edges; + std::vector<weight_t> _vertices; int _last_state; test_case_map_type _test; base_logger::stat _stat; std::string _suite_name; + void run_test_case( vertex_t v ); + static bool vertices_compare( weight_t, weight_t ); + static int _root_func( test_suite *, int = 0 ); static base_logger *logger; @@ -247,8 +237,9 @@ template <class TC> test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name ) { - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( root, v, g ); + vertex_t v = ++_count; + _edges.push_back( std::make_pair( 0, v ) ); + _vertices.push_back( std::make_pair( v, 1 ) ); _test[v].tc = detail::make_test_case( f, instance ); _test[v].state = 0; _test[v].name = name; @@ -260,10 +251,16 @@ template <class InputIter> test_suite::test_case_type test_suite::add( test_suite::func_type f, const std::string& name, InputIter first, InputIter last ) { - vertex_t v = boost::add_vertex( boost::white_color, g); + vertex_t v = ++_count; + unsigned weight = 1; while ( first != last ) { - boost::add_edge( *first++, v, g ); + if ( *first >= _count ) { + throw std::logic_error( "bad test dependency" ); + } + weight += _vertices[*first].second; + _edges.push_back( std::make_pair( *first++, v ) ); } + _vertices.push_back( std::make_pair( v, weight ) ); _test[v].tc = detail::make_test_case( detail::call( f ) ); _test[v].state = 0; _test[v].name = name; @@ -275,8 +272,12 @@ template <class TC> test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, test_suite::test_case_type depends ) { - vertex_t v = boost::add_vertex( boost::white_color, g); - boost::add_edge( depends, v, g ); + vertex_t v = ++_count; + if ( depends >= _count ) { + throw std::logic_error( "bad test dependency" ); + } + _edges.push_back( std::make_pair( depends, v ) ); + _vertices.push_back( std::make_pair( v, _vertices[depends].second + 1 ) ); _test[v].tc = detail::make_test_case( f, instance ); _test[v].state = 0; _test[v].name = name; @@ -288,10 +289,16 @@ template <class TC, class InputIter> test_suite::test_case_type test_suite::add( int (TC::*f)( test_suite *, int ), TC& instance, const std::string& name, InputIter first, InputIter last ) { - vertex_t v = boost::add_vertex( boost::white_color, g); + vertex_t v = ++_count; + unsigned weight = 1; while ( first != last ) { - boost::add_edge( *first++, v, g ); + if ( *first >= _count ) { + throw std::logic_error( "bad test dependency" ); + } + weight += _vertices[*first].second; + _edges.push_back( std::make_pair( *first++, v ) ); } + _vertices.push_back( std::make_pair( v, weight ) ); _test[v].tc = detail::make_test_case( f, instance ); _test[v].state = 0; _test[v].name = name; Modified: trunk/complement/explore/lib/exam/ChangeLog =================================================================== --- trunk/complement/explore/lib/exam/ChangeLog 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/lib/exam/ChangeLog 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,3 +1,11 @@ +2007-07-21 Petr Ovtchenkov <pt...@is...> + + * suite.h, suite.cc: boost graph removed; + + * ut/exam_test_suite.cc: problem with multiple dependencies resolved. + + * libexam: version 0.2.0 + 2007-07-17 Petr Ovtchenkov <pt...@is...> * suite.h, suite.cc: was introduced stack of test suites, functions Modified: trunk/complement/explore/lib/exam/Makefile.inc =================================================================== --- trunk/complement/explore/lib/exam/Makefile.inc 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/lib/exam/Makefile.inc 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,7 +1,7 @@ -# -*- Makefile -*- Time-stamp: <07/07/16 00:51:47 ptr> +# -*- Makefile -*- Time-stamp: <07/07/21 09:21:58 ptr> LIBNAME = exam MAJOR = 0 -MINOR = 1 +MINOR = 2 PATCH = 0 SRC_CC = logger.cc suite.cc Modified: trunk/complement/explore/lib/exam/suite.cc =================================================================== --- trunk/complement/explore/lib/exam/suite.cc 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/lib/exam/suite.cc 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,11 +1,12 @@ -// -*- C++ -*- Time-stamp: <07/07/17 10:03:02 ptr> +// -*- C++ -*- Time-stamp: <07/07/21 09:13:17 ptr> #include <exam/suite.h> -#include <boost/graph/breadth_first_search.hpp> #include <stack> #include <cstdio> #include <iostream> +#include <algorithm> +#include <functional> namespace exam { @@ -14,85 +15,7 @@ using namespace detail; using namespace xmt; -namespace detail { -template <class Tag> -struct vertex_recorder : - public base_visitor<vertex_recorder<Tag> > -{ - typedef Tag event_filter; - - vertex_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { _suite.run_test_case( v ); } - - test_suite& _suite; -}; - -template <class Tag> -vertex_recorder<Tag> record_vertexes(test_suite& ts, Tag) -{ return vertex_recorder<Tag>(ts); } - -template <class Tag> -struct skip_recorder : - public base_visitor<skip_recorder<Tag> > -{ - typedef Tag event_filter; - - skip_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Edge, class Graph> - void operator()(Edge e, const Graph& g) - { - // typename graph_traits<Graph>::vertex_descriptor u = boost::source( e, g ); - // typename graph_traits<Graph>::vertex_descriptor v = boost::target( e, g ); - // boost::out_edges( v, g ); - // for () { - _suite.check_test_case( boost::source( e, g ), boost::target( e, g ) ); - // } - } - - test_suite& _suite; -}; - -template <class Tag> -skip_recorder<Tag> record_skip(test_suite& ts, Tag) -{ return skip_recorder<Tag>(ts); } - -template <class Tag> -struct white_recorder : - public base_visitor<white_recorder<Tag> > -{ - typedef Tag event_filter; - - white_recorder(test_suite& ts) : - _suite(ts) - { } - - template <class Vertex, class Graph> - void operator()(Vertex v, const Graph& g) - { - // std::cerr << "On vertex " << v << std::endl; - // boost::put( boost::vertex_color, g, v, white_color ); - _suite.clean_test_case_state( v ); - } - - test_suite& _suite; -}; - -template <class Tag> -white_recorder<Tag> record_white(test_suite& ts, Tag) -{ return white_recorder<Tag>(ts); } - - -} // namespace detail - int EXAM_IMPL(test_suite::_root_func) { throw init_exception(); @@ -101,28 +24,28 @@ } test_suite::test_suite( const string& name ) : - root( add_vertex( white_color, g ) ), - _last_state( 0 ), - _suite_name( name ), - local_logger( logger ) + _count(0), + _last_state( 0 ), + _suite_name( name ), + local_logger( logger ) { - testcase = get( vertex_testcase, g ); - _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); - _test[root].state = 0; + _vertices.push_back( std::make_pair( 0, 0 ) ); + _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[0].state = 0; scoped_lock lk( _lock_stack ); _stack.push( this ); } test_suite::test_suite( const char *name ) : - root( add_vertex( white_color, g ) ), - _last_state( 0 ), - _suite_name( name ), - local_logger( logger ) + _count(0), + _last_state( 0 ), + _suite_name( name ), + local_logger( logger ) { - testcase = get( vertex_testcase, g ); - _test[root].tc = detail::make_test_case( detail::call( _root_func ) ); - _test[root].state = 0; + _vertices.push_back( std::make_pair( 0, 0 ) ); + _test[0].tc = detail::make_test_case( detail::call( _root_func ) ); + _test[0].state = 0; scoped_lock lk( _lock_stack ); _stack.push( this ); @@ -139,28 +62,38 @@ } } +bool test_suite::vertices_compare( test_suite::weight_t l, test_suite::weight_t r ) +{ + return l.second < r.second; +} + int test_suite::girdle( test_suite::test_case_type start ) { - stack<vertex_t> buffer; - vertex_color_map_t color = get( vertex_color, g ); + if ( start > _count ) { + throw std::logic_error( "bad start point" ); + } - // detail::white_recorder<on_initialize_vertex> vis( *this ); - // - // vertex_iterator_t i, i_end; + sort( _vertices.begin(), _vertices.end(), vertices_compare ); - // for ( tie(i, i_end) = vertices(g); i != i_end; ++i ) { - // // vis.initialize_vertex( *i, g ); - // put( color, *i, white_color ); - // } + 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(); - breadth_first_search( g, start, buffer, - make_bfs_visitor( - make_pair( record_white(*this,on_initialize_vertex()), - make_pair( record_vertexes(*this,on_discover_vertex()), - record_skip(*this,on_examine_edge()) ) ) ), - color ); + 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; + } + } + run_test_case( i->first ); + } + local_logger->end_ts(); local_logger->result( _stat, _suite_name ); @@ -169,8 +102,9 @@ test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name ) { - vertex_t v = add_vertex( white_color, g); - add_edge( root, v, g ); + vertex_t v = ++_count; + _edges.push_back( std::make_pair( 0, v ) ); + _vertices.push_back( std::make_pair( v, 1 ) ); _test[v].tc = detail::make_test_case( detail::call( f ) ); _test[v].state = 0; _test[v].name = name; @@ -181,8 +115,12 @@ test_suite::test_case_type test_suite::add( test_suite::func_type f, const string& name, test_suite::test_case_type depends ) { - vertex_t v = add_vertex( white_color, g); - add_edge( depends, v, g ); + vertex_t v = ++_count; + if ( depends >= _count ) { + throw std::logic_error( "bad test dependency" ); + } + _edges.push_back( std::make_pair( depends, v ) ); + _vertices.push_back( std::make_pair( v, _vertices[depends].second + 1 ) ); _test[v].tc = detail::make_test_case( detail::call( f ) ); _test[v].state = 0; _test[v].name = name; @@ -300,21 +238,9 @@ } } -void test_suite::check_test_case( test_suite::vertex_t u, test_suite::vertex_t v ) -{ - if ( _test[u].state != 0 ) { - _test[v].state = skip; - } -} - -void test_suite::clean_test_case_state( vertex_t v ) -{ - _test[v].state = 0; -} - int test_suite::run( test_suite *, int ) { - return girdle( root ); + return girdle( 0 ); } Modified: trunk/complement/explore/lib/exam/ut/Makefile =================================================================== --- trunk/complement/explore/lib/exam/ut/Makefile 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/lib/exam/ut/Makefile 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,11 +1,10 @@ -# -*- Makefile -*- Time-stamp: <07/07/05 09:31:15 ptr> +# -*- Makefile -*- Time-stamp: <07/07/21 09:01:38 ptr> SRCROOT := ../../.. include Makefile.inc include ${SRCROOT}/Makefiles/gmake/top.mak -# INCLUDES += -I${BOOST_DIR} INCLUDES += -I${CoMT_INCLUDE_DIR} DEFS += -D__FIT_EXAM Modified: trunk/complement/explore/lib/exam/ut/exam_test_suite.cc =================================================================== --- trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-20 06:10:55 UTC (rev 1633) +++ trunk/complement/explore/lib/exam/ut/exam_test_suite.cc 2007-07-21 05:47:37 UTC (rev 1634) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <07/07/17 00:38:11 ptr> +// -*- C++ -*- Time-stamp: <07/07/21 09:01:26 ptr> #include "exam_test_suite.h" @@ -220,15 +220,15 @@ tcx[1] = t.add( func_good2, "function 2 good", tc, tc + 2 ); t.add( func_good3, "function 3 good", tcx, tcx + 2 ); // <-- problem - logger.flags( exam::base_logger::verbose ); + // logger.flags( exam::base_logger::verbose ); t.girdle(); - logger.flags( 0 ); + // logger.flags( 0 ); - // EXAM_REQUIRE( buff.str() == r9 ); + EXAM_REQUIRE( buff.str() == r9 ); - std::cerr << "%%%\n"; - std::cerr << buff.str() << std::endl; - std::cerr << "%%%\n"; + // std::cerr << "%%%\n"; + // std::cerr << buff.str() << std::endl; + // std::cerr << "%%%\n"; return EXAM_RESULT; } @@ -266,16 +266,16 @@ dummy_test.cc:16: fail: false\n\ dummy_test.cc:17: pass: true\n\ FAIL member function fail\n\ +dummy_test.cc:33: pass: true\n\ SKIP function fail\n\ -dummy_test.cc:33: pass: true\n\ *** FAIL exam self test, fail function (+2-1~1/4) ***\n"; const std::string exam_basic_test::r6 = "\ PASS member function good\n\ dummy_test.cc:16: fail: false\n\ FAIL member function fail\n\ + PASS function good\n\ SKIP function fail\n\ - PASS function good\n\ *** FAIL exam self test, fail function (+2-1~1/4) ***\n"; const std::string exam_basic_test::r7 = "\ @@ -299,6 +299,7 @@ FAIL function fail\n\ dummy_test.cc:16: fail: false\n\ FAIL member function fail\n\ + SKIP function 3 good\n\ *** FAIL exam self test, fail function (+3-2~1/6) ***\n"; int EXAM_IMPL(exam_self_test) @@ -312,7 +313,7 @@ t.add( &exam_basic_test::trace, exam_basic, "trace flags test", d ); t.add( &exam_basic_test::dep_test_suite, exam_basic, "test suites grouping", d ); exam::test_suite::test_case_type d2 = t.add( &exam_basic_test::multiple_dep, exam_basic, "multiple dependencies", d ); - // t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); + t.add( &exam_basic_test::multiple_dep_complex, exam_basic, "complex multiple dependencies", d2 ); return t.girdle(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |