blob: 3f4f98d3683b390625f086f07544d71710cad794 [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();
48}
49
onqtam4a655632016-05-26 14:20:52 +030050SCENARIO("vectors can be sized and resized") {
51 GIVEN("A vector with some items") {
52 std::vector<int> v(5);
53
onqtamf90739e2016-09-14 01:01:45 +030054 REQUIRE(v.size() == 5);
55 REQUIRE(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030056
57 WHEN("the size is increased") {
onqtamf90739e2016-09-14 01:01:45 +030058 v.resize(10);
onqtam4a655632016-05-26 14:20:52 +030059
60 THEN("the size and capacity change") {
onqtamf90739e2016-09-14 01:01:45 +030061 CHECK(v.size() == 20);
62 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030063 }
64 }
65 WHEN("the size is reduced") {
66 v.resize(0);
67
68 THEN("the size changes but not capacity") {
onqtamf90739e2016-09-14 01:01:45 +030069 CHECK(v.size() == 0);
70 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030071 }
72 }
73 WHEN("more capacity is reserved") {
74 v.reserve(10);
75
76 THEN("the capacity changes but not the size") {
onqtamf90739e2016-09-14 01:01:45 +030077 CHECK(v.size() == 5);
78 CHECK(v.capacity() >= 10);
onqtam4a655632016-05-26 14:20:52 +030079 }
80 }
81 WHEN("less capacity is reserved") {
82 v.reserve(0);
83
84 THEN("neither size nor capacity are changed") {
onqtamf90739e2016-09-14 01:01:45 +030085 CHECK(v.size() == 10);
86 CHECK(v.capacity() >= 5);
onqtam4a655632016-05-26 14:20:52 +030087 }
88 }
89 }
90}