Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

basic_sequence.h

Go to the documentation of this file.
00001 #ifndef STATIC_CONTIANER_TEST_BASIC_SEQUENCE_H
00002 
00003 #define STATIC_CONTIANER_TEST_BASIC_SEQUENCE_H
00004 
00005 #include <gslib/numeric.h>
00006 #include <boost/assert.hpp>
00007 #include <gslib/test/del_counter.h>
00008 
00010 template < typename ContGen >
00011 void basic_sequence() {
00012     using namespace gslib;
00013     using namespace test;
00014     using namespace static_container;
00015     
00016     struct local_func {
00017         static void test_del_counter() {
00018             const size_t    size = 10;
00019             typedef ContGen::gen< del_counter, size >::type Cont;
00020             BOOST_REQUIRE( size == Cont::max_size() );
00021             int del_count = 0;
00022             {
00023                 Cont cont;
00024                 BOOST_REQUIRE( cont.empty() );
00025                 BOOST_REQUIRE( 0 == cont.size() );
00026                 cont.push_back( del_counter( del_count ) );
00027                 //  一時オブジェクトの破棄を確認
00028                 BOOST_REQUIRE( 1 == del_count );
00029                 BOOST_REQUIRE( !cont.empty() );
00030                 BOOST_REQUIRE( 1 == cont.size() );
00031             }
00032             //  cont のデストラクタによる解放を確認
00033             BOOST_REQUIRE( 2 == del_count );
00034             
00035             del_count = 0;
00036             {
00037                 Cont cont;
00038                 for ( size_t i = 0; i < size; ++i ) {
00039                     cont.push_back( del_counter( del_count ) );
00040                     BOOST_REQUIRE( i + 1 == cont.size() );
00041                 }
00042                 BOOST_REQUIRE( 10 == del_count );
00043                 for ( size_t i = 0; i < size; ++i ) {
00044                     cont.pop_back();
00045                     BOOST_REQUIRE( size - i - 1 == cont.size() );
00046                 }
00047                 BOOST_REQUIRE( 20 == del_count );
00048             }
00049             BOOST_REQUIRE( 20 == del_count );
00050 
00051             del_count = 0;
00052             {
00053                 Cont cont;
00054                 for ( size_t i = 0; i < size; ++i ) {
00055                     cont.push_back( del_counter( del_count ) );
00056                     BOOST_REQUIRE( i + 1 == cont.size() );
00057                 }
00058                 BOOST_REQUIRE( 10 == del_count );
00059                 cont.clear();
00060                 BOOST_REQUIRE( 20 == del_count );
00061             }
00062             BOOST_REQUIRE( 20 == del_count );
00063         }
00064         
00065         static void test_int() {
00066             const size_t size = 10;
00067             typedef ContGen::gen< int, size >::type Cont;
00068             typedef Cont::iterator          iterator;
00069             typedef Cont::const_iterator    const_iterator;
00070             BOOST_REQUIRE( size == Cont::max_size() );
00071             
00072             Cont cont;
00073             cont.push_back( 123 );
00074             BOOST_REQUIRE( 123 == cont.front() );
00075             cont.front() = 33;
00076             BOOST_REQUIRE( 33 == cont.front() );
00077             cont.push_back( 53 );
00078             BOOST_REQUIRE( 33 == cont.front() );
00079             BOOST_REQUIRE( 53 == cont.back() );
00080             
00081             Cont::iterator it = cont.begin();
00082             BOOST_REQUIRE( 33 == *it );
00083             ++it;
00084             BOOST_REQUIRE( 53 == *it );
00085             
00086             Cont another( cont );
00087             BOOST_REQUIRE( another == cont );
00088             cont.push_back( 0 );
00089             BOOST_REQUIRE( another != cont );
00090             BOOST_REQUIRE( another < cont );
00091             ++another.back();
00092             BOOST_REQUIRE( cont < another );
00093             another = cont;
00094             BOOST_REQUIRE( cont == another );
00095             cont = cont; // 自己代入テスト
00096             BOOST_REQUIRE( cont == another );
00097             
00098             cont.clear();
00099             
00100             for ( int i = 0; i < static_cast< int >( size ); ++i ) {
00101                 cont.push_back( i );
00102             }
00103             for ( iterator it = cont.begin(); it != cont.end(); ++it ) {
00104                     BOOST_REQUIRE( std::distance( cont.begin(), it ) == *it );
00105             }
00106             cont.clear();
00107             
00108             //  iterator から const_iterator への暗黙のキャストは可能か?
00109             const_iterator cit = cont.begin();
00110             
00111             //  多重クリア
00112             for ( int i = 0; i < 10; ++i ) {
00113                 cont.clear();
00114             }
00115         }
00116     };
00117     
00118     local_func::test_del_counter();
00119     local_func::test_int();
00120 }
00121 
00122 #endif

Generated on Sat Nov 27 15:02:48 2004 for static_container by doxygen 1.3.6