-
Notifications
You must be signed in to change notification settings - Fork 44
/
10-bdd.cpp
66 lines (52 loc) · 1.8 KB
/
10-bdd.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
// C++11 - use BDD style, adapted from Catch tutorial.
#include "lest/lest.hpp"
#include <vector>
using text = std::string;
const lest::test specification[] = {
SCENARIO( "vectors can be sized and resized" "[vector]" ) {
GIVEN( "A vector with some items" ) {
std::vector<int> v( 5 );
EXPECT( v.size() == 5u );
EXPECT( v.capacity() >= 5u );
WHEN( "the size is increased" ) {
v.resize( 10 );
THEN( "the size and capacity change" ) {
EXPECT( v.size() == 10u);
EXPECT( v.capacity() >= 10u );
}
}
WHEN( "the size is reduced" ) {
v.resize( 0 );
THEN( "the size changes but not capacity" ) {
EXPECT( v.size() == 0u );
EXPECT( v.capacity() >= 5u );
}
}
WHEN( "more capacity is reserved" ) {
v.reserve( 10 );
THEN( "the capacity changes but not the size" ) {
EXPECT( v.size() == 5u );
EXPECT( v.capacity() >= 10u );
}
WHEN( "less capacity is reserved again" ) {
v.reserve( 7 );
THEN( "capacity remains unchanged" ) {
EXPECT( v.capacity() >= 10u );
}
}
}
WHEN( "less capacity is reserved" ) {
v.reserve( 0 );
THEN( "neither size nor capacity are changed" ) {
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 10-bdd.cpp && 10-bdd
// g++ -Wall -Wextra -Wmissing-include-dirs -std=c++11 -I../include -o 10-bdd.exe 10-bdd.cpp && 10-bdd