00001 #include <gslib/test/assert_new.h>
00002 #define BOOST_AUTO_TEST_MAIN
00003 #include <boost/test/auto_unit_test.hpp>
00004 #include <gslib/static_container/list.h>
00005 #include "basic_sequence.h"
00006 #include <iterator>
00007 #include <boost/iterator/counting_iterator.hpp>
00008
00009 using namespace gslib;
00010 using namespace static_container;
00011
00012 struct listgen {
00013 template < typename Value, size_t Size >
00014 struct gen {
00015 typedef list< Value, Size > type;
00016 };
00017 };
00018
00019 BOOST_AUTO_UNIT_TEST( test_list_basic ) {
00020 test::assert_new::begin();
00021 basic_sequence< listgen >();
00022 test::assert_new::end();
00023 }
00024
00025 BOOST_AUTO_UNIT_TEST( test_lodge_list ) {
00026 test::assert_new::begin();
00027 list_node_pool< int, 10 > pool;
00028 lodge_list< int > list0( pool );
00029 lodge_list< int > list1( pool );
00030 lodge_list< int > list2( pool );
00031
00032 BOOST_REQUIRE( 10 == pool.rest() );
00033 BOOST_REQUIRE( list0.empty() );
00034 list0.push_back( 100 );
00035 BOOST_REQUIRE( 1 == list0.size() );
00036 BOOST_REQUIRE( 9 == pool.rest() );
00037 BOOST_REQUIRE( 100 == list0.front() );
00038
00039 list1.push_back( 10 );
00040 list2.push_back( 5 );
00041 list0.push_back( 9 );
00042 BOOST_REQUIRE( 6 == pool.rest() );
00043 list1.pop_back();
00044 BOOST_REQUIRE( 7 == pool.rest() );
00045
00046
00047 list0.clear();
00048 BOOST_REQUIRE( list0.empty() );
00049 BOOST_REQUIRE( 9 == pool.rest() );
00050
00051 std::copy( boost::counting_iterator< int >( 0 ), boost::counting_iterator< int >( pool.rest() ), std::back_inserter( list1 ) );
00052 BOOST_REQUIRE( 0 == pool.rest() );
00053
00054 BOOST_REQUIRE( list1.end() != std::find( list1.begin(), list1.end(), 5 ) );
00055 lodge_list< int >::iterator it = list1.begin();
00056 std::advance( it, 5 );
00057 list1.erase( it );
00058 BOOST_REQUIRE( list1.end() == std::find( list1.begin(), list1.end(), 5 ) );
00059 test::assert_new::end();
00060 }