blob: 626a28666ec87115650ad587ba032db593aaa6bc [file] [log] [blame]
onqtam862a3bb2016-04-27 18:19:00 +03001//#define DOCTEST_CONFIG_DISABLE
hardlyb1e7e142014-08-06 00:43:51 +03002
onqtamcae73122016-04-29 14:57:23 +03003#include "doctest.h"
onqtam862a3bb2016-04-27 18:19:00 +03004#define DOCTEST_CONFIG_IMPLEMENT
hardlyb1e7e142014-08-06 00:43:51 +03005#include "doctest.h"
6
7#include <cstdio>
onqtamcae73122016-04-29 14:57:23 +03008#include <cstdlib>
onqtam42869192016-05-15 19:06:24 +03009#include <vector>
onqtam1d145062016-05-18 12:52:45 +030010//#include <ostream>
onqtam42869192016-05-15 19:06:24 +030011
12//template <typename T>
13//std::ostream& operator<<(std::ostream& s, const std::vector<T>& in) {
14// s << "[";
15// for(size_t i = 0; i < in.size(); ++i)
16// if(i < in.size() - 1)
17// s << in[i] << ", ";
18// else
19// s << in[i];
20// s << "]";
21// return s;
22//}
onqtame08cd402016-05-16 19:18:25 +030023
onqtam1d145062016-05-18 12:52:45 +030024#include <algorithm>
25#include <limits>
26#include <cmath>
27
onqtame08cd402016-05-16 19:18:25 +030028
onqtame08cd402016-05-16 19:18:25 +030029
onqtamfd527f92016-05-19 15:45:39 +030030SCENARIO("[math]vectors can be sized and resized") {
onqtame08cd402016-05-16 19:18:25 +030031
onqtamfd527f92016-05-19 15:45:39 +030032 GIVEN("A vector with some items") {
33 std::vector<int> v(5);
34
35 REQUIRE(v.size() == 5u);
36 REQUIRE(v.capacity() >= 5u);
37
38 WHEN("the size is increased") {
39 v.resize(10);
40
41 THEN("the size and capacity change") {
42 REQUIRE(v.size() == 10u);
43 REQUIRE(v.capacity() >= 10u);
44 }
45 }
46 WHEN("the size is reduced") {
47 v.resize(0);
48
49 THEN("the size changes but not capacity") {
50 REQUIRE(v.size() == 0u);
51 REQUIRE(v.capacity() >= 5u);
52 }
53 }
54 WHEN("more capacity is reserved") {
55 v.reserve(10);
56
57 THEN("the capacity changes but not the size") {
58 REQUIRE(v.size() == 5u);
59 REQUIRE(v.capacity() >= 10u);
60 }
61 }
62 WHEN("less capacity is reserved") {
63 v.reserve(0);
64
65 THEN("neither size nor capacity are changed") {
66 REQUIRE(v.size() == 5u);
67 REQUIRE(v.capacity() >= 5u);
68 }
69 }
70 }
onqtame08cd402016-05-16 19:18:25 +030071}
hardlyb1e7e142014-08-06 00:43:51 +030072
onqtamfd527f92016-05-19 15:45:39 +030073//TEST_CASE("zzz") {
74// //CHECK(std::string("OMG2") == std::string("OMG"));
75//
76// std::vector<int> vec1;
77// vec1.push_back(1);
78// vec1.push_back(2);
79// vec1.push_back(3);
80//
81// std::vector<int> vec2;
82// vec2.push_back(1);
83// vec2.push_back(2);
84// vec2.push_back(4);
85//
86// //CHECK(vec1 == vec2);
87//}
88
hardlyb1e7e142014-08-06 00:43:51 +030089int main(int argc, char** argv) {
90 // initialize
91 doctest::Context context(argc, argv);
hardlyb1e7e142014-08-06 00:43:51 +030092
93 // overrides
94 context.setOption("dt-case-sensitive", true);
onqtam862a3bb2016-04-27 18:19:00 +030095 context.setOption("no-breaks", true);
onqtam7049f402016-05-12 23:58:59 +030096 //context.setOption("success", true);
onqtamad0d6d22016-05-11 17:46:02 +030097 //context.setOption("no-throw", true);
onqtam0cea9bc2016-04-27 12:59:08 +030098 //context.setOption("dt-no-colors", true);
onqtamfd527f92016-05-19 15:45:39 +030099 //context.addFilter("test-case", "zzz");
onqtam3af136c2016-05-12 18:05:18 +0300100 //context.setOption("abort-after", 1);
onqtam76c13642016-05-11 17:30:29 +0300101 //context.addFilter("suite", "randomness");
102 //context.setOption("sort", "rand");
103 //context.setOption("rand-seed", 435);
hardlyb1e7e142014-08-06 00:43:51 +0300104
105 // run
onqtamb91b68e2016-05-04 20:16:19 +0300106 int res = context.run();
107
108 if(context.shouldExit())
109 return res;
hardlyb1e7e142014-08-06 00:43:51 +0300110
111#if defined(WITH_PAUSE)
112 system("pause");
onqtam8ccce3b2016-04-20 20:46:05 +0300113#endif // WITH_PAUSE
hardlyb1e7e142014-08-06 00:43:51 +0300114
115 return res;
116}