[complement-svn] SF.net SVN: complement: [1568] trunk/complement/explore/test/virtual_time
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2007-05-22 15:05:07
|
Revision: 1568 http://svn.sourceforge.net/complement/?rev=1568&view=rev Author: complement Date: 2007-05-22 08:05:03 -0700 (Tue, 22 May 2007) Log Message: ----------- development; tests Modified Paths: -------------- trunk/complement/explore/test/virtual_time/vtime.cc trunk/complement/explore/test/virtual_time/vtime.h Added Paths: ----------- trunk/complement/explore/test/virtual_time/test/ trunk/complement/explore/test/virtual_time/test/Makefile trunk/complement/explore/test/virtual_time/test/Makefile.inc trunk/complement/explore/test/virtual_time/test/unit_test.cc Property changes on: trunk/complement/explore/test/virtual_time/test ___________________________________________________________________ Name: svn:ignore + obj Added: trunk/complement/explore/test/virtual_time/test/Makefile =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile (rev 0) +++ trunk/complement/explore/test/virtual_time/test/Makefile 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,38 @@ +# -*- Makefile -*- Time-stamp: <07/02/21 15:30:59 ptr> + +SRCROOT := ../../.. +COMPILER_NAME := gcc +# ALL_TAGS := install-release-shared install-dbg-shared +# CoMT_DIR := ../../external/complement/explore + +include Makefile.inc +include ${SRCROOT}/Makefiles/top.mak + +# DEFS += -DUNIT_TEST +INCLUDES += -I${CoMT_INCLUDE_DIR} -I${BOOST_INCLUDE_DIR} -I.. + +LDFLAGS += -L${INSTALL_LIB_DIR} -Wl,-rpath=${INSTALL_LIB_DIR} + +release-shared: PROJECT_LIBS = -lxmt -lsockios -lstem -lboost_regex -lboost_test_utf -lboost_fs +dbg-shared: PROJECT_LIBS = -lxmtg -lsockiosg -lstemg -lboost_regexg -lboost_test_utfg -lboost_fsg +stldbg-shared: PROJECT_LIBS = -lxmtstlg -lsockiosstlg -lstemstlg -lboost_regexstlg -lboost_test_utfstlg -lboost_fsstlg + +LDLIBS = ${PROJECT_LIBS} + +check: all-shared + ${OUTPUT_DIR}/${PRGNAME} || exit 1 + ${OUTPUT_DIR_DBG}/${PRGNAME} || exit 1 +ifndef WITHOUT_STLPORT + ${OUTPUT_DIR_STLDBG}/${PRGNAME} || exit 1; +endif + +check-release-shared: release-shared + ${OUTPUT_DIR}/${PRGNAME} || exit 1 + +check-dbg-shared: dbg-shared + ${OUTPUT_DIR_DBG}/${PRGNAME} || exit 1 + +ifndef WITHOUT_STLPORT +check-stldbg-shared: stldbg-shared + ${OUTPUT_DIR_STLDBG}/${PRGNAME} || exit 1 +endif Added: trunk/complement/explore/test/virtual_time/test/Makefile.inc =================================================================== --- trunk/complement/explore/test/virtual_time/test/Makefile.inc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/Makefile.inc 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,8 @@ +# -*- Makefile -*- + +PRGNAME = ut_vtime + +SRC_CC = ../vtime.cc \ + unit_test.cc + + Added: trunk/complement/explore/test/virtual_time/test/unit_test.cc =================================================================== --- trunk/complement/explore/test/virtual_time/test/unit_test.cc (rev 0) +++ trunk/complement/explore/test/virtual_time/test/unit_test.cc 2007-05-22 15:05:03 UTC (rev 1568) @@ -0,0 +1,244 @@ +// -*- C++ -*- Time-stamp: <07/03/07 16:38:24 ptr> + +#include <boost/test/unit_test.hpp> + +#include <boost/lexical_cast.hpp> + +#include <string> +#include <iostream> + +#include <vtime.h> + +using namespace boost::unit_test_framework; +using namespace vt; +using namespace std; + +struct vtime_operations +{ + void vt_compare(); + void vt_add(); + void vt_diff(); + void vt_max(); +}; + +void vtime_operations::vt_compare() +{ + vtime_type vt1; + vtime_type vt2; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( vt1 == vt2 ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( vt2 <= vt1 ); + + vt2.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( !(vt1 == vt2) ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( !(vt2 <= vt1) ); + + vt1.clear(); + vt2.clear(); + + vt1.push_back( make_pair( 1, 1 ) ); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( !(vt1 == vt2) ); + BOOST_CHECK( vt1 <= vt2 ); + BOOST_CHECK( !(vt2 <= vt1) ); + + vt1.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( !(vt1 <= vt2) ); + BOOST_CHECK( !(vt2 <= vt1) ); +} + +void vtime_operations::vt_add() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 + vt2; + + BOOST_CHECK( vt1 == vt3 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 + vt2; + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt4.clear(); + + vt2.push_back( make_pair( 3, 1 ) ); + + vt3 = vt1 + vt2; + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + vt4.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); +} + +void vtime_operations::vt_diff() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt1 - vt2; + + BOOST_CHECK( vt1 == vt3 ); + + vt2.push_back( make_pair( 1, 1 ) ); + + vt3 = vt1 - vt2; + + vt4.push_back( make_pair( 2, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt4.clear(); + + vt3 = vt1 - vt2; + + BOOST_CHECK( vt3 == vt4 ); + + vt2.clear(); + + vt2.push_back( make_pair( 3, 1 ) ); + + try { + vt3 = vt1 - vt2; + BOOST_CHECK( false ); + } + catch ( const std::range_error& err ) { + BOOST_CHECK( true ); + } + + vt2.clear(); + + vt2.push_back( make_pair( 2, 2 ) ); + + try { + vt3 = vt1 - vt2; + BOOST_CHECK( false ); + } + catch ( const std::range_error& err ) { + BOOST_CHECK( true ); + } +} + +void vtime_operations::vt_max() +{ + vtime_type vt1; + vtime_type vt2; + vtime_type vt3; + vtime_type vt4; + + vt1.push_back( make_pair( 1, 1 ) ); + vt1.push_back( make_pair( 2, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 1, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 2, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + BOOST_CHECK( vt3 == vt1 ); + + vt2.push_back( make_pair( 3, 1 ) ); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 1 ) ); + vt4.push_back( make_pair( 3, 1 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.clear(); + + vt2.push_back( make_pair( 1, 1 ) ); + vt2.push_back( make_pair( 2, 2 ) ); + + vt4.clear(); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 1, 1 ) ); + vt4.push_back( make_pair( 2, 2 ) ); + + BOOST_CHECK( vt3 == vt4 ); + + vt2.push_back( make_pair( 3, 4 ) ); + + vt3 = vt::max( vt1, vt2 ); + + vt4.push_back( make_pair( 3, 4 ) ); + + BOOST_CHECK( vt3 == vt4 ); +} + +struct vtime_test_suite : + public boost::unit_test_framework::test_suite +{ + vtime_test_suite(); +}; + +vtime_test_suite::vtime_test_suite() : + test_suite( "vtime test suite" ) +{ + boost::shared_ptr<vtime_operations> vt_op_instance( new vtime_operations() ); + + test_case *vt_compare_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_compare, vt_op_instance ); + test_case *vt_add_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_add, vt_op_instance ); + test_case *vt_diff_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_diff, vt_op_instance ); + test_case *vt_max_tc = BOOST_CLASS_TEST_CASE( &vtime_operations::vt_max, vt_op_instance ); + + // long_msg_tc->depends_on( init_tc ); + + add( vt_compare_tc ); + add( vt_add_tc ); + add( vt_diff_tc ); + add( vt_max_tc ); + // add( service_tc ); +} + +test_suite *init_unit_test_suite( int argc, char **argv ) +{ + test_suite *ts = BOOST_TEST_SUITE( "vtime test" ); + ts->add( new vtime_test_suite() ); + + return ts; +} Modified: trunk/complement/explore/test/virtual_time/vtime.cc =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-21 13:50:00 UTC (rev 1567) +++ trunk/complement/explore/test/virtual_time/vtime.cc 2007-05-22 15:05:03 UTC (rev 1568) @@ -142,7 +142,7 @@ if ( i->first < j->first ) { // v <= 0 --- false return false; } - while ( i->first > j->first && j != r.end() ) { // 0 <= v --- true + while ( j != r.end() && i->first > j->first ) { // 0 <= v --- true ++j; } @@ -173,12 +173,12 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { + while ( i != l.end() && j != r.end() && i->first == j->first ) { if ( i->second < j->second ) { throw range_error( "vtime different: right value grater then left" ); } else if ( i->second > j->second ) { @@ -216,12 +216,12 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { + while ( i != l.end() && j != r.end() && i->first == j->first ) { vt.push_back( make_pair( i->first, i->second + j->second ) ); ++i; ++j; @@ -232,7 +232,7 @@ vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( j != l.end() ) { + while ( j != r.end() ) { vt.push_back( make_pair( j->first, j->second ) ); ++j; } @@ -258,13 +258,13 @@ vtime_type::const_iterator j = r.begin(); while ( i != l.end() && j != r.end() ) { - while ( i->first < j->first && i != l.end() ) { + while ( i != l.end() && i->first < j->first ) { vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( i->first == j->first && i != l.end() && j != r.end() ) { - vt.push_back( make_pair( i->first, max( i->second, j->second ) ) ); + while ( i != l.end() && j != r.end() && i->first == j->first ) { + vt.push_back( make_pair( i->first, std::max( i->second, j->second ) ) ); ++i; ++j; } @@ -273,7 +273,7 @@ vt.push_back( make_pair( i->first, i->second ) ); ++i; } - while ( j != l.end() ) { + while ( j != r.end() ) { vt.push_back( make_pair( j->first, j->second ) ); ++j; } @@ -286,16 +286,16 @@ cout << ev.value().mess << endl; } -bool order_correct( const stem::Event_base<VTmess>& ev ) +bool Proc::order_correct( const stem::Event_base<VTmess>& ev ) { // assume here first_group - gvtime_type::const_iterator gr = ev.value().gvt.begin(); - gvtime_type::const_iterator ge = ev.value().gvt.end(); + gvtime_type::const_iterator gr = ev.value().gvt.gvt.begin(); + gvtime_type::const_iterator ge = ev.value().gvt.gvt.end(); - for ( ; gr != ge; ++i ) { + for ( ; gr != ge; ++gr ) { if ( gr->first == first_group ) { - vtime_type vt_tmp = last_vt[first_group] + gr->second; + vtime_type vt_tmp = last_vt[first_group] + gr->second.vt; vtime_type::const_iterator i = vt_tmp.begin(); vtime_type::const_iterator j = vt[first_group].begin(); @@ -331,7 +331,7 @@ } } } else { - vtime_type vt_tmp = last_vt[second_group] + gr->second; + vtime_type vt_tmp = last_vt[second_group] + gr->second.vt; if ( !(vt_tmp <= vt[second_group] )) { return false; } Modified: trunk/complement/explore/test/virtual_time/vtime.h =================================================================== --- trunk/complement/explore/test/virtual_time/vtime.h 2007-05-21 13:50:00 UTC (rev 1567) +++ trunk/complement/explore/test/virtual_time/vtime.h 2007-05-22 15:05:03 UTC (rev 1568) @@ -54,49 +54,10 @@ throw std::invalid_argument( "uncomparable vtime" ); } - -#if 0 -bool operator <=( const vtime_type& l, const vtime_type& r ) -{ - if ( l.size() == 0 ) { // 0 always less or equal of anything - return true; - } - - bool result = true; - vtime_type::const_iterator i = l.begin(); - vtime_type::const_iterator j = r.begin(); - - while ( j->first < i->first && j != r.end() ) { - ++j; - } - - if ( j == r.end() ) { // note, that i != l.end() here! - return false; - } - - for ( ; i != l.end() && j != r.end(); ) { - if ( i->second > j->second ) { - } - - if ( i->first < j->first ) { - ++i; - } else if ( i->first == j->first ) { - if ( i->second > j->second ) { - return false; - } - } else { - ++j; - } - } -} -#endif - - bool operator <=( const vtime_type& l, const vtime_type& r ); vtime_type operator -( const vtime_type& l, const vtime_type& r ); vtime_type operator +( const vtime_type& l, const vtime_type& r ); -template <> vtime_type max( const vtime_type& l, const vtime_type& r ); struct vtime : @@ -184,8 +145,8 @@ n_groups }; - std::vector<vtime_type> vt[n_groups]; - std::vector<vtime_type> last_vt[n_groups]; + vtime_type vt[n_groups]; + vtime_type last_vt[n_groups]; DECLARE_RESPONSE_TABLE( Proc, stem::EventHandler ); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |