Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
120-Bdd-ScenarioGivenWhenThen.cpp
Go to the documentation of this file.
1// 120-Bdd-ScenarioGivenWhenThen.cpp
2
3// main() provided in 000-CatchMain.cpp
4
5#include <catch2/catch.hpp>
6
7SCENARIO( "vectors can be sized and resized", "[vector]" ) {
8
9 GIVEN( "A vector with some items" ) {
10 std::vector<int> v( 5 );
11
12 REQUIRE( v.size() == 5 );
13 REQUIRE( v.capacity() >= 5 );
14
15 WHEN( "the size is increased" ) {
16 v.resize( 10 );
17
18 THEN( "the size and capacity change" ) {
19 REQUIRE( v.size() == 10 );
20 REQUIRE( v.capacity() >= 10 );
21 }
22 }
23 WHEN( "the size is reduced" ) {
24 v.resize( 0 );
25
26 THEN( "the size changes but not capacity" ) {
27 REQUIRE( v.size() == 0 );
28 REQUIRE( v.capacity() >= 5 );
29 }
30 }
31 WHEN( "more capacity is reserved" ) {
32 v.reserve( 10 );
33
34 THEN( "the capacity changes but not the size" ) {
35 REQUIRE( v.size() == 5 );
36 REQUIRE( v.capacity() >= 10 );
37 }
38 }
39 WHEN( "less capacity is reserved" ) {
40 v.reserve( 0 );
41
42 THEN( "neither size nor capacity are changed" ) {
43 REQUIRE( v.size() == 5 );
44 REQUIRE( v.capacity() >= 5 );
45 }
46 }
47 }
48}
49
50// Compile & run:
51// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 120-Bdd-ScenarioGivenWhenThen 120-Bdd-ScenarioGivenWhenThen.cpp 000-CatchMain.o && 120-Bdd-ScenarioGivenWhenThen --success
52// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 120-Bdd-ScenarioGivenWhenThen.cpp 000-CatchMain.obj && 120-Bdd-ScenarioGivenWhenThen --success
53
54// Expected compact output (all assertions):
55//
56// prompt> 120-Bdd-ScenarioGivenWhenThen.exe --reporter compact --success
57// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
58// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
59// 120-Bdd-ScenarioGivenWhenThen.cpp:19: passed: v.size() == 10 for: 10 == 10
60// 120-Bdd-ScenarioGivenWhenThen.cpp:20: passed: v.capacity() >= 10 for: 10 >= 10
61// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
62// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
63// 120-Bdd-ScenarioGivenWhenThen.cpp:27: passed: v.size() == 0 for: 0 == 0
64// 120-Bdd-ScenarioGivenWhenThen.cpp:28: passed: v.capacity() >= 5 for: 5 >= 5
65// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
66// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
67// 120-Bdd-ScenarioGivenWhenThen.cpp:35: passed: v.size() == 5 for: 5 == 5
68// 120-Bdd-ScenarioGivenWhenThen.cpp:36: passed: v.capacity() >= 10 for: 10 >= 10
69// 120-Bdd-ScenarioGivenWhenThen.cpp:12: passed: v.size() == 5 for: 5 == 5
70// 120-Bdd-ScenarioGivenWhenThen.cpp:13: passed: v.capacity() >= 5 for: 5 >= 5
71// 120-Bdd-ScenarioGivenWhenThen.cpp:43: passed: v.size() == 5 for: 5 == 5
72// 120-Bdd-ScenarioGivenWhenThen.cpp:44: passed: v.capacity() >= 5 for: 5 >= 5
73// Passed 1 test case with 16 assertions.
#define THEN(desc)
Definition catch.hpp:266
#define GIVEN(desc)
Definition catch.hpp:262
#define WHEN(desc)
Definition catch.hpp:264
#define SCENARIO(...)
Definition catch.hpp:259
#define REQUIRE(...)
Definition catch.hpp:185