-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffer-test.cpp
68 lines (57 loc) · 1.41 KB
/
buffer-test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "buffer.h"
int main() {
Buffer< int > buf( 16 );
for ( int i = 0; i < 16; ++i ) {
buf.push_back( i );
assert( buf.size() == i + 1 );
}
for ( int i = 0; i < 16; ++i )
assert( buf[ i ] == i );
for ( int i = 16; i < 64; ++i ) {
buf.push_back( i );
assert( buf.size() == 16 );
}
for ( int i = 0; i < 16; ++i )
assert( buf[ i ] == 48 + i );
{
int i = 48;
for ( auto x : buf )
assert( x == i++ );
assert( i == 64 );
}
for ( int i = 0; i < 8; ++i )
buf.push_back( i );
for ( int i = 0; i < 8; ++i )
assert( buf[ i ] == 56 + i );
for ( int i = 8; i < 16; ++i )
assert( buf[ i ] == i - 8 );
for ( int i = 0; i < 8; ++i ) {
assert( buf.front() == 56 + i );
buf.pop_front();
assert( buf.size() == 16 - i - 1 );
}
assert( buf.size() == 8 );
{
int i = 0;
for ( auto x : buf )
assert( x == i++ );
assert( i == 8 );
}
for ( int i = 8; i < 24; ++i ) {
buf.push_back( i );
assert( buf.size() == std::min( i + 1, 16 ) );
}
{
int i = 8;
for ( auto x : buf )
assert( x == i++ );
assert( i == 24 );
}
buf.pop_back();
{
int i = 8;
for ( auto x : buf )
assert( x == i++ );
assert( i == 23 );
}
}