| 15 | protected: |
| 16 | template <typename Queue> |
| 17 | void test( Queue& q ) |
| 18 | { |
| 19 | typedef typename Queue::value_type value_type; |
| 20 | value_type it; |
| 21 | |
| 22 | const size_t nSize = 100; |
| 23 | |
| 24 | ASSERT_TRUE( q.empty()); |
| 25 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 26 | |
| 27 | // enqueue/dequeue |
| 28 | for ( size_t i = 0; i < nSize; ++i ) { |
| 29 | it = static_cast<value_type>(i); |
| 30 | ASSERT_TRUE( q.enqueue( it )); |
| 31 | ASSERT_CONTAINER_SIZE( q, i + 1 ); |
| 32 | } |
| 33 | ASSERT_FALSE( q.empty()); |
| 34 | ASSERT_CONTAINER_SIZE( q, nSize ); |
| 35 | |
| 36 | for ( size_t i = 0; i < nSize; ++i ) { |
| 37 | it = -1; |
| 38 | ASSERT_TRUE( q.dequeue( it )); |
| 39 | ASSERT_EQ( it, static_cast<value_type>( i )); |
| 40 | ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); |
| 41 | } |
| 42 | ASSERT_TRUE( q.empty()); |
| 43 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 44 | |
| 45 | // push/pop |
| 46 | for ( size_t i = 0; i < nSize; ++i ) { |
| 47 | it = static_cast<value_type>(i); |
| 48 | ASSERT_TRUE( q.push( it )); |
| 49 | ASSERT_CONTAINER_SIZE( q, i + 1 ); |
| 50 | } |
| 51 | ASSERT_FALSE( q.empty()); |
| 52 | ASSERT_CONTAINER_SIZE( q, nSize ); |
| 53 | |
| 54 | for ( size_t i = 0; i < nSize; ++i ) { |
| 55 | it = -1; |
| 56 | ASSERT_TRUE( q.pop( it )); |
| 57 | ASSERT_EQ( it, static_cast<value_type>( i )); |
| 58 | ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); |
| 59 | } |
| 60 | ASSERT_TRUE( q.empty()); |
| 61 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 62 | |
| 63 | // push/pop with lambda |
| 64 | for ( size_t i = 0; i < nSize; ++i ) { |
| 65 | it = static_cast<value_type>(i); |
| 66 | ASSERT_NE( it, -1 ); |
| 67 | auto f = [&it]( value_type& dest ) { dest = it; it = -1; }; |
| 68 | if ( i & 1 ) |
| 69 | ASSERT_TRUE( q.enqueue_with( f )); |
| 70 | else |
| 71 | ASSERT_TRUE( q.push_with( f )); |
| 72 | ASSERT_EQ( it, -1 ); |
| 73 | ASSERT_CONTAINER_SIZE( q, i + 1 ); |
| 74 | } |
nothing calls this directly
no test coverage detected