@@ -134,142 +134,83 @@ namespace {
134
134
" buggy_function2" );
135
135
}
136
136
137
- static bool comparator (const std::string firstVar, const std::string secondVar, bool mustEqual, bool isInt){
138
- if (isInt) {
139
- if (mustEqual) return std::stoi (firstVar) == std::stoi (secondVar);
140
- return std::stoi (firstVar) != std::stoi (secondVar);
141
- }
142
- if (mustEqual) return std::stod (firstVar) == std::stod (secondVar);
143
- return std::stod (firstVar) != std::stod (secondVar);
137
+ static bool checkEquals (const tests::Tests::TestCaseParamValue& first, const tests::Tests::TestCaseParamValue& second){
138
+ return std::stoi (first.view ->getEntryValue (nullptr )) == std::stoi (second.view ->getEntryValue (nullptr ));
144
139
}
145
140
146
- static bool simpleCheckerForPair (const std::vector<std::string>& variables, bool isInt, bool diffVars){
147
- return comparator (variables[0 ], variables[2 ], !diffVars, isInt) &&
148
- comparator (variables[0 ], variables[3 ], true , isInt) &&
149
- comparator (variables[1 ], variables[2 ], true , isInt);
141
+ void checkDifferentVariablesTrue_C (BaseTestGen &testGen){
142
+ checkDifferentVariables_C (testGen, true );
150
143
}
151
144
152
- static bool commonSimpleChecker (const std::vector<std::string>& variables, bool isInt, bool diffVars){
153
- if (variables.size () == 4 ) {return simpleCheckerForPair (variables, isInt, diffVars);}
154
- return simpleCheckerForPair (std::vector<std::string>(variables.begin (), variables.begin () + 4 ), isInt, diffVars) &&
155
- simpleCheckerForPair (std::vector<std::string>(variables.begin () + 4 , variables.end ()), isInt, diffVars);
145
+ void checkDifferentVariablesFalse_C (BaseTestGen &testGen){
146
+ checkDifferentVariables_C (testGen, false );
156
147
}
157
148
158
- void checkDifferentVariablesTrue_C (BaseTestGen &testGen) {
149
+ void checkDifferentVariables_C (BaseTestGen &testGen, bool differentVariables) {
159
150
for (const auto &[methodName, methodDescription] :
160
151
testGen.tests .at (different_variables_c).methods ) {
161
152
if (methodName == " swap_two_int_pointers" ) {
162
153
checkTestCasePredicates (
163
154
methodDescription.testCases ,
164
155
std::vector<TestCasePredicate>(
165
- { [](tests::Tests::MethodTestCase const &testCase) {
166
- return commonSimpleChecker ({testCase.paramValues [0 ]
167
- .view ->getEntryValue (nullptr ),
168
- testCase.paramPostValues [0 ]
169
- .view ->getEntryValue (nullptr ),
170
- testCase.paramValues [1 ]
171
- .view ->getEntryValue (nullptr ),
172
- testCase.paramPostValues [1 ]
173
- .view ->getEntryValue (nullptr )},
174
- true , true ) &&
156
+ { [differentVariables](tests::Tests::MethodTestCase const &testCase) {
157
+ return (differentVariables ^
158
+ checkEquals (testCase.paramValues [0 ],
159
+ testCase.paramValues [1 ])) &&
160
+ checkEquals (testCase.paramPostValues [0 ],
161
+ testCase.paramValues [1 ]) &&
162
+ checkEquals (testCase.paramPostValues [1 ],
163
+ testCase.paramValues [0 ]) &&
175
164
testCase.stdinValue == std::nullopt;
176
165
} }),
177
166
methodName);
178
167
} else if (methodName == " max_of_two_float" ) {
179
168
checkTestCasePredicates (
180
169
methodDescription.testCases ,
181
170
std::vector<TestCasePredicate>(
182
- { [](tests::Tests::MethodTestCase const &testCase) {
183
- return stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )) !=
184
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr )) &&
171
+ { [differentVariables](tests::Tests::MethodTestCase const &testCase) {
172
+ return ((stod (testCase.paramValues [0 ].view ->getEntryValue (
173
+ nullptr )) ==
174
+ stod (testCase.paramValues [1 ].view ->getEntryValue (
175
+ nullptr ))) ^
176
+ differentVariables) &&
185
177
stod (testCase.returnValue .view ->getEntryValue (nullptr )) ==
186
- std::max (stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )),
187
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr ))) &&
178
+ std::max (
179
+ stod (testCase.paramValues [0 ].view ->getEntryValue (
180
+ nullptr )),
181
+ stod (testCase.paramValues [1 ].view ->getEntryValue (
182
+ nullptr ))) &&
188
183
testCase.stdinValue == std::nullopt;
189
184
},
190
185
[](tests::Tests::MethodTestCase const &testCase) {
191
- return stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )) !=
192
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr )) &&
186
+ return stod (testCase.paramValues [0 ].view ->getEntryValue (
187
+ nullptr )) !=
188
+ stod (testCase.paramValues [1 ].view ->getEntryValue (
189
+ nullptr )) &&
193
190
stod (testCase.returnValue .view ->getEntryValue (nullptr )) ==
194
- std::max (stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )),
195
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr ))) &&
191
+ std::max (
192
+ stod (testCase.paramValues [0 ].view ->getEntryValue (
193
+ nullptr )),
194
+ stod (testCase.paramValues [1 ].view ->getEntryValue (
195
+ nullptr ))) &&
196
196
testCase.stdinValue == std::nullopt;
197
197
} }),
198
198
methodName);
199
199
} else if (methodName == " struct_test" ) {
200
- checkTestCasePredicates (
201
- methodDescription.testCases ,
202
- std::vector<TestCasePredicate>(
203
- {
204
- [](tests::Tests::MethodTestCase const &testCase) {
205
- return testCase.returnValue .view ->getEntryValue (nullptr ) == " -1" ;
206
- },
207
- [](tests::Tests::MethodTestCase const &testCase) {
208
- return testCase.returnValue .view ->getEntryValue (nullptr ) == " 1" ;
209
- } }),
210
- methodName);
211
- }
212
- }
213
- }
214
-
215
- void checkDifferentVariablesFalse_C (BaseTestGen &testGen){
216
- for (const auto &[methodName, methodDescription] :
217
- testGen.tests .at (different_variables_c).methods ) {
218
- if (methodName == " swap_two_int_pointers" ) {
219
200
checkTestCasePredicates (
220
201
methodDescription.testCases ,
221
202
std::vector<TestCasePredicate>(
222
203
{ [](tests::Tests::MethodTestCase const &testCase) {
223
- return commonSimpleChecker ({testCase.paramValues [0 ]
224
- .view ->getEntryValue (nullptr ),
225
- testCase.paramPostValues [0 ]
226
- .view ->getEntryValue (nullptr ),
227
- testCase.paramValues [1 ]
228
- .view ->getEntryValue (nullptr ),
229
- testCase.paramPostValues [1 ]
230
- .view ->getEntryValue (nullptr )},
231
- true , false ) &&
232
- testCase.stdinValue == std::nullopt;
233
- } }),
234
- methodName);
235
- } else if (methodName == " max_of_two_float" ) {
236
- checkTestCasePredicates (
237
- methodDescription.testCases ,
238
- std::vector<TestCasePredicate>(
239
- { [](tests::Tests::MethodTestCase const &testCase) {
240
- return stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )) !=
241
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr )) &&
242
- stod (testCase.returnValue .view ->getEntryValue (nullptr )) ==
243
- std::max (stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )),
244
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr ))) &&
245
- testCase.stdinValue == std::nullopt;
204
+ return testCase.returnValue .view ->getEntryValue (nullptr ) == " -1" ;
246
205
},
247
206
[](tests::Tests::MethodTestCase const &testCase) {
248
- return stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )) ==
249
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr )) &&
250
- stod (testCase.returnValue .view ->getEntryValue (nullptr )) ==
251
- std::max (stod (testCase.paramValues [0 ].view ->getEntryValue (nullptr )),
252
- stod (testCase.paramValues [1 ].view ->getEntryValue (nullptr ))) &&
253
- testCase.stdinValue == std::nullopt;
207
+ return testCase.returnValue .view ->getEntryValue (nullptr ) == " 1" ;
254
208
} }),
255
209
methodName);
256
- } else if (methodName == " struct_test" ) {
257
- checkTestCasePredicates (
258
- methodDescription.testCases ,
259
- std::vector<TestCasePredicate>(
260
- {
261
- [](tests::Tests::MethodTestCase const &testCase) {
262
- return testCase.returnValue .view ->getEntryValue (nullptr ) == " -1" ;
263
- },
264
- [](tests::Tests::MethodTestCase const &testCase) {
265
- return testCase.returnValue .view ->getEntryValue (nullptr ) == " 1" ;
266
- } }),
267
- methodName);
268
210
}
269
211
}
270
212
}
271
213
272
-
273
214
void checkBasicFunctions_C (BaseTestGen &testGen) {
274
215
EXPECT_EQ (printer::TestsPrinter::needsMathHeader (testGen.tests .at (basic_functions_c)),
275
216
false );
0 commit comments