-
Notifications
You must be signed in to change notification settings - Fork 0
/
testMultipleVariadicArguments.cpp
193 lines (171 loc) · 8.43 KB
/
testMultipleVariadicArguments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdint.h>
#include <iostream>
#include <string>
#include <catch.hpp>
#include "multipleVariadicArguments.hpp"
#include "testMultipleVariadicArgumentsObjects.hpp"
using std::string;
SCENARIO("Part of the solution to having multiple variadic arguments is knowing where the separator is located") {
GIVEN("Function calls to the separator handler") {
WHEN("We call the separator with only the separator object value") {
THEN("The separator exists in the list") {
REQUIRE(hasSeparator(multipleVariadicArgumentSeparator) == true);
}
THEN("We must find the corresponding indices") {
REQUIRE(MultipleVariadicArgumentSeparatorHandler<MultipleVariadicArgumentSeparator>::SeparatorPosition == 0U);
REQUIRE(findSeparatorPosition(multipleVariadicArgumentSeparator) == 0U);
}
}
WHEN("We call the separator with no separator object values") {
uint32_t testObject1 = 5U;
string testObject2("test");
double testObject3 = 0.9;
THEN("The separator does not exist in the list") {
REQUIRE(hasSeparator(testObject1) == false);
REQUIRE(hasSeparator(testObject1, testObject2) == false);
REQUIRE(hasSeparator(testObject1, testObject2, testObject3) == false);
}
THEN("We must find the size indices") {
uint32_t sepPosition1 = MultipleVariadicArgumentSeparatorHandler<uint32_t>::SeparatorPosition;
REQUIRE(sepPosition1 == 1U);
REQUIRE(findSeparatorPosition(testObject1) == 1U);
uint32_t sepPosition2 = MultipleVariadicArgumentSeparatorHandler<uint32_t, string>::SeparatorPosition;
REQUIRE(sepPosition2 == 2U);
REQUIRE(findSeparatorPosition(testObject1, testObject2) == 2U);
uint32_t sepPosition3 = MultipleVariadicArgumentSeparatorHandler<uint32_t, string, double>::SeparatorPosition;
REQUIRE(sepPosition3 == 3U);
REQUIRE(findSeparatorPosition(testObject1, testObject2, testObject3) == 3U);
}
}
WHEN("We call the separator with some objects before the separator object value") {
uint32_t testObject1 = 5U;
THEN("The separator exists in the list") {
REQUIRE(hasSeparator(testObject1, multipleVariadicArgumentSeparator) == true);
}
THEN("We must find the corresponding indices") {
uint32_t sepPosition = MultipleVariadicArgumentSeparatorHandler<uint32_t, MultipleVariadicArgumentSeparator>::SeparatorPosition;
REQUIRE(sepPosition == 1U);
REQUIRE(findSeparatorPosition(testObject1, multipleVariadicArgumentSeparator) == 1U);
}
}
WHEN("We call the separator with some objects after the separator object value") {
uint32_t testObject1 = 5U;
THEN("The separator exists in the list") {
REQUIRE(hasSeparator(multipleVariadicArgumentSeparator, testObject1) == true);
}
THEN("We must find the corresponding indices") {
uint32_t sepPosition = MultipleVariadicArgumentSeparatorHandler<MultipleVariadicArgumentSeparator, uint32_t>::SeparatorPosition;
REQUIRE(sepPosition == 0U);
REQUIRE(findSeparatorPosition(multipleVariadicArgumentSeparator, testObject1) == 0U);
}
}
WHEN("We call the separator with some objects before and after the separator object value") {
uint32_t testObject1 = 5U;
string testObject2("Test");
THEN("The separator exists in the list") {
REQUIRE(hasSeparator(testObject2, multipleVariadicArgumentSeparator, testObject1) == true);
}
THEN("We must find the corresponding indices") {
uint32_t sepPosition = MultipleVariadicArgumentSeparatorHandler<string, MultipleVariadicArgumentSeparator, uint32_t>::SeparatorPosition;
REQUIRE(sepPosition == 1U);
REQUIRE(findSeparatorPosition(testObject2, multipleVariadicArgumentSeparator, testObject1) == 1U);
}
}
WHEN("We invent some more difficult scenario's") {
THEN("They must also effortlessly succeed") {
REQUIRE(findSeparatorPosition(5U, 7U, "hello", multipleVariadicArgumentSeparator, 7.0, 5.0f) == 3U);
REQUIRE(findSeparatorPosition(5U, 7U, "hello", 7.0, 5.0f, multipleVariadicArgumentSeparator, "World") == 5U);
}
}
WHEN("We call the separator with no values at all") {
THEN("The separator does not exist in the list") {
REQUIRE(hasSeparator() == false);
}
THEN("We must find the corresponding indices") {
REQUIRE(MultipleVariadicArgumentSeparatorHandler<>::SeparatorPosition == 0U);
REQUIRE(findSeparatorPosition() == 0U);
}
}
}
}
SCENARIO("Call a function using multiple variadic arguments") {
GIVEN("A functor accepting the exact number of the argument pack") {
const uint32_t initValue = MultipleVariadicArgumentTestObject::getInitialIntValue();
const uint32_t newValue = initValue + 5U;
const double initDoubleValue = MultipleVariadicArgumentTestObject::getInitialDoubleValue();
const double newDoubleValue = initDoubleValue * 5;
MultipleVariadicArgumentTestObject testObject;
WHEN("We try to call this functor with no arguments") {
callMultipleArgumentFunction(testObject);
THEN("No values of the test object should have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 1U);
REQUIRE(testObject.getIntValue1() == initValue);
REQUIRE(testObject.getIntValue2() == initValue);
REQUIRE(testObject.getDoubleValue1() == initValue);
}
}
WHEN("We call the test object with a specified number of arguments") {
callMultipleArgumentFunction(testObject, newValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == initValue);
REQUIRE(testObject.getDoubleValue1() == initValue);
}
}
WHEN("We call the test object with a specified number of arguments") {
callMultipleArgumentFunction(testObject, newValue, newValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == newValue);
REQUIRE(testObject.getDoubleValue1() == initValue);
}
}
WHEN("We call the test object with a specified number of arguments") {
callMultipleArgumentFunction(testObject, newValue, newDoubleValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == initValue);
REQUIRE(testObject.getDoubleValue1() == newDoubleValue);
}
}
WHEN("We call the test object with a specified number of arguments") {
callMultipleArgumentFunction(testObject, newValue, newDoubleValue, newValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == newValue);
REQUIRE(testObject.getDoubleValue1() == newDoubleValue);
}
}
WHEN("We call the test object number of arguments before the separator") {
callMultipleArgumentFunction(testObject, newValue, newDoubleValue, newValue, multipleVariadicArgumentSeparator);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == newValue);
REQUIRE(testObject.getDoubleValue1() == newDoubleValue);
}
}
WHEN("We call the test object with a number of arguments after the separator") {
callMultipleArgumentFunction(testObject, multipleVariadicArgumentSeparator, newValue, newDoubleValue, newValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 1U); // For the empty functor call before the separator
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == newValue);
REQUIRE(testObject.getDoubleValue1() == newDoubleValue);
}
}
WHEN("We call the test object with a number of arguments before and after the separator") {
callMultipleArgumentFunction(testObject, newValue, multipleVariadicArgumentSeparator, newDoubleValue);
THEN("The corresponding values of the test object must have changed") {
REQUIRE(testObject.getNbOfTimesEmptyFunctorCalled() == 0U);
REQUIRE(testObject.getIntValue1() == newValue);
REQUIRE(testObject.getIntValue2() == initValue);
REQUIRE(testObject.getDoubleValue1() == newDoubleValue);
}
}
}
}