Progmasoft Git

catch3

Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.

Clonegit clone https://git.progmasoft.com/catch3

Added vector resize test

Commit
29426b6359af60d6a49d7d444fbfabdf401ffe14
Author
Phil Nash ·
Parents
2e3c5fa2ade5

Files · Download .tar.gz

Changes

 projects/SelfTest/MiscTests.cpp | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/projects/SelfTest/MiscTests.cpp b/projects/SelfTest/MiscTests.cpp
index d0b61b0c..edbda6e1 100644
--- a/projects/SelfTest/MiscTests.cpp
+++ b/projects/SelfTest/MiscTests.cpp
@@ -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 );
+    }
+}