Skip to content

Instantly share code, notes, and snippets.

@junaidrahim
Created June 11, 2019 15:40
Show Gist options
  • Save junaidrahim/0a823b395219047ab9e3d61e76b964c0 to your computer and use it in GitHub Desktop.
Save junaidrahim/0a823b395219047ab9e3d61e76b964c0 to your computer and use it in GitHub Desktop.
Test cases and sections from the catch2 github repo
TEST_CASE( "vectors can be sized and resized", "[vector]" ) {
std::vector<int> v( 5 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 5 );
SECTION( "resizing bigger changes size and capacity" ) {
v.resize( 10 );
REQUIRE( v.size() == 10 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "resizing smaller changes size but not capacity" ) {
v.resize( 0 );
REQUIRE( v.size() == 0 );
REQUIRE( v.capacity() >= 5 );
}
SECTION( "reserving bigger changes capacity but not size" ) {
v.reserve( 10 );
REQUIRE( v.size() == 5 );
REQUIRE( v.capacity() >= 10 );
}
SECTION( "reserving smaller does not change size or capacity" ) {
v.reserve( 0 );
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