blob: 430e69b523fc2bfbbd670acc14cb91b20143dfb7 [file] [log] [blame]
onqtam4a655632016-05-26 14:20:52 +03001#include "doctest.h"
2
onqtam7cc0e962017-04-17 23:30:36 +03003#include "header.h"
4
onqtam4a655632016-05-26 14:20:52 +03005#include <iostream>
6#include <vector>
7using namespace std;
8
onqtam4a655632016-05-26 14:20:52 +03009TEST_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!
onqtam7cc0e962017-04-17 23:30:36 +030020 FAIL("");
onqtam4a655632016-05-26 14:20:52 +030021
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
onqtam378d6702017-04-19 11:30:03 +030034static void call_func() {
onqtam5dbcb1e2017-05-02 23:07:56 +030035 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 }
onqtam378d6702017-04-19 11:30:03 +030043 }
44}
45
46TEST_CASE("subcases can be used in a separate function as well") {
47 call_func();
onqtama82c1e42017-05-07 17:36:41 +030048 MESSAGE("lala");
onqtam378d6702017-04-19 11:30:03 +030049}
50
onqtam4a655632016-05-26 14:20:52 +030051SCENARIO("vectors can be sized and resized") {
52 GIVEN("A vector with some items") {
53 std::vector<int> v(5);
54
onqtamf90739e2016-09-14 01:01:45 +030055 REQUIRE(v.size() == 5);
56 REQUIRE(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030057
58 WHEN("the size is increased") {
onqtamf90739e2016-09-14 01:01:45 +030059 v.resize(10);
onqtam4a655632016-05-26 14:20:52 +030060
61 THEN("the size and capacity change") {
onqtamf90739e2016-09-14 01:01:45 +030062 CHECK(v.size() == 20);
63 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030064 }
65 }
66 WHEN("the size is reduced") {
67 v.resize(0);
68
69 THEN("the size changes but not capacity") {
onqtamf90739e2016-09-14 01:01:45 +030070 CHECK(v.size() == 0);
71 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030072 }
73 }
74 WHEN("more capacity is reserved") {
75 v.reserve(10);
76
77 THEN("the capacity changes but not the size") {
onqtamf90739e2016-09-14 01:01:45 +030078 CHECK(v.size() == 5);
79 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030080 }
81 }
82 WHEN("less capacity is reserved") {
83 v.reserve(0);
84
85 THEN("neither size nor capacity are changed") {
onqtamf90739e2016-09-14 01:01:45 +030086 CHECK(v.size() == 10);
87 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030088 }
89 }
90 }
91}