Skip to content

Commit 2738572

Browse files
committed
tests_fixing_2
1 parent 814d27a commit 2738572

File tree

1 file changed

+37
-96
lines changed

1 file changed

+37
-96
lines changed

server/test/framework/Server_Tests.cpp

Lines changed: 37 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -134,142 +134,83 @@ namespace {
134134
"buggy_function2");
135135
}
136136

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));
144139
}
145140

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);
150143
}
151144

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);
156147
}
157148

158-
void checkDifferentVariablesTrue_C(BaseTestGen &testGen){
149+
void checkDifferentVariables_C(BaseTestGen &testGen, bool differentVariables) {
159150
for (const auto &[methodName, methodDescription] :
160151
testGen.tests.at(different_variables_c).methods) {
161152
if (methodName == "swap_two_int_pointers") {
162153
checkTestCasePredicates(
163154
methodDescription.testCases,
164155
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]) &&
175164
testCase.stdinValue == std::nullopt;
176165
} }),
177166
methodName);
178167
} else if (methodName == "max_of_two_float") {
179168
checkTestCasePredicates(
180169
methodDescription.testCases,
181170
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) &&
185177
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))) &&
188183
testCase.stdinValue == std::nullopt;
189184
},
190185
[](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)) &&
193190
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))) &&
196196
testCase.stdinValue == std::nullopt;
197197
} }),
198198
methodName);
199199
} 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") {
219200
checkTestCasePredicates(
220201
methodDescription.testCases,
221202
std::vector<TestCasePredicate>(
222203
{ [](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";
246205
},
247206
[](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";
254208
} }),
255209
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);
268210
}
269211
}
270212
}
271213

272-
273214
void checkBasicFunctions_C(BaseTestGen &testGen) {
274215
EXPECT_EQ(printer::TestsPrinter::needsMathHeader(testGen.tests.at(basic_functions_c)),
275216
false);

0 commit comments

Comments
 (0)