| 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 = q.capacity(); |
| 23 | |
| 24 | ASSERT_TRUE( q.empty()); |
| 25 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 26 | |
| 27 | // enqueue/dequeue |
| 28 | for ( unsigned pass = 0; pass < 3; ++pass ) { |
| 29 | for ( size_t i = 0; i < nSize; ++i ) { |
| 30 | it = static_cast<value_type>( i ); |
| 31 | ASSERT_TRUE( q.enqueue( it )); |
| 32 | ASSERT_CONTAINER_SIZE( q, i + 1 ); |
| 33 | } |
| 34 | ASSERT_FALSE( q.empty()); |
| 35 | ASSERT_CONTAINER_SIZE( q, nSize ); |
| 36 | ASSERT_FALSE( q.enqueue( static_cast<value_type>( nSize ) * 2 )); |
| 37 | |
| 38 | for ( size_t i = 0; i < nSize; ++i ) { |
| 39 | it = -1; |
| 40 | ASSERT_TRUE( q.dequeue( it )); |
| 41 | ASSERT_EQ( it, static_cast<value_type>( i )); |
| 42 | ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); |
| 43 | } |
| 44 | ASSERT_TRUE( q.empty()); |
| 45 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 46 | } |
| 47 | |
| 48 | // push/pop |
| 49 | for ( unsigned pass = 0; pass < 3; ++pass ) { |
| 50 | for ( size_t i = 0; i < nSize; ++i ) { |
| 51 | it = static_cast<value_type>( i ); |
| 52 | ASSERT_TRUE( q.push( it )); |
| 53 | ASSERT_CONTAINER_SIZE( q, i + 1 ); |
| 54 | } |
| 55 | ASSERT_FALSE( q.empty()); |
| 56 | ASSERT_CONTAINER_SIZE( q, nSize ); |
| 57 | |
| 58 | for ( size_t i = 0; i < nSize; ++i ) { |
| 59 | it = -1; |
| 60 | ASSERT_TRUE( q.pop( it )); |
| 61 | ASSERT_EQ( it, static_cast<value_type>( i )); |
| 62 | ASSERT_CONTAINER_SIZE( q, nSize - i - 1 ); |
| 63 | } |
| 64 | ASSERT_TRUE( q.empty()); |
| 65 | ASSERT_CONTAINER_SIZE( q, 0 ); |
| 66 | } |
| 67 | |
| 68 | // push/pop with lambda |
| 69 | for ( unsigned pass = 0; pass < 3; ++pass ) { |
| 70 | for ( size_t i = 0; i < nSize; ++i ) { |
| 71 | it = static_cast<value_type>( i ); |
| 72 | ASSERT_NE( it, -1 ); |
| 73 | auto f = [&it]( value_type& dest ) { dest = it; it = -1; }; |
| 74 | if ( i & 1 ) |
nothing calls this directly
no test coverage detected