-
Notifications
You must be signed in to change notification settings - Fork 44
/
09-fixture.cpp
57 lines (42 loc) · 1.55 KB
/
09-fixture.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
// C++11 - use a fixture, adapted from Catch tutorial.
#include "lest/lest.hpp"
#include <vector>
using text = std::string;
const lest::test specification[] = {
CASE( "vectors can be sized and resized" "[vector]" ) {
SETUP( "A vector with some items" ) {
std::vector<int> v( 5 );
EXPECT( v.size() == 5u );
EXPECT( v.capacity() >= 5u );
SECTION( "resizing bigger changes size and capacity" ) {
v.resize( 10 );
EXPECT( v.size() == 10u );
EXPECT( v.capacity() >= 10u );
}
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
EXPECT( v.size() == 0u );
EXPECT( v.capacity() >= 5u );
}
SECTION( "reserving bigger changes capacity but not size" ) {
v.reserve( 10 );
EXPECT( v.size() == 5u );
EXPECT( v.capacity() >= 10u );
SECTION( "reserving smaller again does not change capacity" ) {
v.reserve( 7 );
EXPECT( v.capacity() >= 10u );
}
}
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
EXPECT( v.size() == 5u );
EXPECT( v.capacity() >= 5u );
}
}
}};
int main( int argc, char * argv[] )
{
return lest::run( specification, argc, argv );
}
// cl -nologo -W3 -EHsc -I../include 09-fixture.cpp && 09-fixture
// g++ -Wall -Wextra -Wmissing-include-dirs -std=c++11 -I../include -o 09-fixture.exe 09-fixture.cpp && 09-fixture