Skip to content

Instantly share code, notes, and snippets.

@junaidrahim
Created June 11, 2019 15:44
Show Gist options
  • Save junaidrahim/a7eb0be0cac30a7eaa722bf3d6196be1 to your computer and use it in GitHub Desktop.
Save junaidrahim/a7eb0be0cac30a7eaa722bf3d6196be1 to your computer and use it in GitHub Desktop.
BDD style specification for catch2 medium post
SCENARIO( "vectors can be sized and resized", "[vector]" ) {
GIVEN( "A vector with some items" ) {
std::vector<int> v( 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
WHEN( "the size is increased" ) {
v.resize( 10 );
THEN( "the size and capacity change" ) {
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
}
}
WHEN( "the size is reduced" ) {
v.resize( 0 );
THEN( "the size changes but not capacity" ) {
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
}
}
WHEN( "more capacity is reserved" ) {
v.reserve( 10 );
THEN( "the capacity changes but not the size" ) {
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
}
}
WHEN( "less capacity is reserved" ) {
v.reserve( 0 );
THEN( "neither size nor capacity are changed" ) {
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment