MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / test

Method test

extern/libcds/test/unit/pqueue/mspqueue.cpp:30–137  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

28 protected:
29 template <class PQueue>
30 void test( PQueue& pq )
31 {
32 data_array<value_type> arr( pq.capacity());
33 value_type * pFirst = arr.begin();
34 value_type * pLast = pFirst + pq.capacity();
35
36 ASSERT_TRUE( pq.empty());
37 ASSERT_EQ( pq.size(), 0u );
38 ASSERT_EQ( pq.capacity(), size_t( base_class::c_nCapacity - 1 ));
39
40 size_t nSize = 0;
41
42 // Push test
43 for ( value_type * p = pFirst; p < pLast; ++p ) {
44 switch ( pq.size() & 3 ) {
45 case 0:
46 ASSERT_TRUE( pq.push_with( [p]( value_type& dest ) { dest = *p; } ));
47 break;
48 case 1:
49 ASSERT_TRUE( pq.emplace( p->k, p->v ));
50 break;
51 case 2:
52 ASSERT_TRUE( pq.emplace( std::make_pair( p->k, p->v )));
53 break;
54 default:
55 ASSERT_TRUE( pq.push( *p ));
56 }
57 ASSERT_TRUE( !pq.empty());
58 ASSERT_TRUE( pq.size() == ++nSize );
59 }
60
61 ASSERT_TRUE( pq.full());
62 ASSERT_EQ( pq.size(), pq.capacity());
63
64 // The queue is full
65 key_type k = base_class::c_nMinValue + key_type( base_class::c_nCapacity );
66 ASSERT_TRUE( !pq.push( k ));
67 ASSERT_TRUE( pq.full());
68 ASSERT_EQ( pq.size(), pq.capacity());
69
70 // Pop test
71 key_type nPrev = base_class::c_nMinValue + key_type( pq.capacity()) - 1;
72 value_type kv( 0 );
73 key_type key;
74 ASSERT_TRUE( pq.pop( kv ));
75 EXPECT_EQ( kv.k, nPrev );
76
77 ASSERT_EQ( pq.size(), pq.capacity() - 1 );
78 ASSERT_TRUE( !pq.full());
79 ASSERT_TRUE( !pq.empty());
80
81 nSize = pq.size();
82 while ( pq.size() > 1 ) {
83 if ( pq.size() & 1 ) {
84 ASSERT_TRUE( pq.pop( kv ));
85 EXPECT_EQ( kv.k, nPrev - 1 );
86 nPrev = kv.k;
87 }

Callers

nothing calls this directly

Calls 15

make_pairFunction · 0.85
key_typeClass · 0.50
refFunction · 0.50
capacityMethod · 0.45
beginMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45
push_withMethod · 0.45
emplaceMethod · 0.45
pushMethod · 0.45
fullMethod · 0.45
popMethod · 0.45

Tested by

no test coverage detected