mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-10-31 20:27:11 +01:00 
			
		
		
		
	Added vector resize test
This commit is contained in:
		| @@ -292,3 +292,43 @@ TEST_CASE( "second tag", "[tag2]" ) | ||||
| //    while ( fgets(line, 199, output) ) | ||||
| //        std::cout << line; | ||||
| //} | ||||
|  | ||||
| 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( "We can use the 'swap trick' to reset the capacity", "" ) { | ||||
|             std::vector<int> empty; | ||||
|             empty.swap( v ); | ||||
|              | ||||
|             REQUIRE( v.capacity() == 0 ); | ||||
|         } | ||||
|     } | ||||
|     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 ); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Phil Nash
					Phil Nash