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 resizing example to BDD tests

Commit
d0df295c25e1967b9bf94cf234a47a80c47b0369
Author
Phil Nash ·
Parents
15fd03260839

Files · Download .tar.gz

Changes

 .../CatchSelfTest/CatchSelfTest/BDDTests.cpp       | 34 ++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest/BDDTests.cpp b/projects/XCode4/CatchSelfTest/CatchSelfTest/BDDTests.cpp
index 900fb8ee..161d8b09 100644
--- a/projects/XCode4/CatchSelfTest/CatchSelfTest/BDDTests.cpp
+++ b/projects/XCode4/CatchSelfTest/CatchSelfTest/BDDTests.cpp
@@ -25,3 +25,37 @@ SCENARIO( "Do that thing with the thing", "[Tags]" ) {
         }
     }
 }
+
+SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capacity]" ) {
+    GIVEN( "an empty vector" ) {
+        std::vector<int> v;
+        REQUIRE( v.size() == 0 );
+        
+        WHEN( "it is made larger" ) {
+            v.resize( 10 );
+            THEN( "the size and capacity go up" ) {
+                REQUIRE( v.size() == 10 );
+                REQUIRE( v.capacity() >= 10 );
+                
+                AND_WHEN( "it is made smaller again" ) {
+                    v.resize( 5 );
+                    THEN( "the size goes down but the capacity stays the same" ) {
+                        REQUIRE( v.size() == 5 );
+                        REQUIRE( v.capacity() >= 10 );
+                    }
+                }
+            }
+        }
+        
+        WHEN( "we reserve more space" ) {
+            v.reserve( 10 );
+            THEN( "The capacity is increased but the size remains the same" ) {
+                REQUIRE( v.capacity() >= 10 );
+                REQUIRE( v.size() == 0 );
+            }
+        }
+    }
+}
+
+SCENARIO( "This is a really long scenario name to see how the list command deals with wrapping", "[very long tags][lots][long][tags][verbose]" ) {
+}