onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 1 | #include "doctest.h" |
| 2 | |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 3 | #include "header.h" |
| 4 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 5 | #include <iostream> |
| 6 | #include <vector> |
| 7 | using namespace std; |
| 8 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 9 | TEST_CASE("lots of nested subcases") { |
| 10 | cout << endl << "root" << endl; |
| 11 | SUBCASE("") { |
| 12 | cout << "1" << endl; |
| 13 | SUBCASE("") { cout << "1.1" << endl; } |
| 14 | } |
| 15 | SUBCASE("") { |
| 16 | cout << "2" << endl; |
| 17 | SUBCASE("") { cout << "2.1" << endl; } |
| 18 | SUBCASE("") { |
| 19 | // whops! all the subcases below shouldn't be discovered and executed! |
onqtam | 7cc0e96 | 2017-04-17 23:30:36 +0300 | [diff] [blame] | 20 | FAIL(""); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 21 | |
| 22 | cout << "2.2" << endl; |
| 23 | SUBCASE("") { |
| 24 | cout << "2.2.1" << endl; |
| 25 | SUBCASE("") { cout << "2.2.1.1" << endl; } |
| 26 | SUBCASE("") { cout << "2.2.1.2" << endl; } |
| 27 | } |
| 28 | } |
| 29 | SUBCASE("") { cout << "2.3" << endl; } |
| 30 | SUBCASE("") { cout << "2.4" << endl; } |
| 31 | } |
| 32 | } |
| 33 | |
onqtam | 378d670 | 2017-04-19 11:30:03 +0300 | [diff] [blame] | 34 | static void call_func() { |
onqtam | 5dbcb1e | 2017-05-02 23:07:56 +0300 | [diff] [blame] | 35 | SUBCASE("from function...") { |
| 36 | MESSAGE("print me twice"); |
| 37 | SUBCASE("sc1") { |
| 38 | MESSAGE("hello! from sc1"); |
| 39 | } |
| 40 | SUBCASE("sc2") { |
| 41 | MESSAGE("hello! from sc2"); |
| 42 | } |
onqtam | 378d670 | 2017-04-19 11:30:03 +0300 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
| 46 | TEST_CASE("subcases can be used in a separate function as well") { |
| 47 | call_func(); |
| 48 | } |
| 49 | |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 50 | SCENARIO("vectors can be sized and resized") { |
| 51 | GIVEN("A vector with some items") { |
| 52 | std::vector<int> v(5); |
| 53 | |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 54 | REQUIRE(v.size() == 5); |
| 55 | REQUIRE(v.capacity() >= 5); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 56 | |
| 57 | WHEN("the size is increased") { |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 58 | v.resize(10); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 59 | |
| 60 | THEN("the size and capacity change") { |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 61 | CHECK(v.size() == 20); |
| 62 | CHECK(v.capacity() >= 10); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | WHEN("the size is reduced") { |
| 66 | v.resize(0); |
| 67 | |
| 68 | THEN("the size changes but not capacity") { |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 69 | CHECK(v.size() == 0); |
| 70 | CHECK(v.capacity() >= 5); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 71 | } |
| 72 | } |
| 73 | WHEN("more capacity is reserved") { |
| 74 | v.reserve(10); |
| 75 | |
| 76 | THEN("the capacity changes but not the size") { |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 77 | CHECK(v.size() == 5); |
| 78 | CHECK(v.capacity() >= 10); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | WHEN("less capacity is reserved") { |
| 82 | v.reserve(0); |
| 83 | |
| 84 | THEN("neither size nor capacity are changed") { |
onqtam | f90739e | 2016-09-14 01:01:45 +0300 | [diff] [blame] | 85 | CHECK(v.size() == 10); |
| 86 | CHECK(v.capacity() >= 5); |
onqtam | 4a65563 | 2016-05-26 14:20:52 +0300 | [diff] [blame] | 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |