Skip to content

Commit b509c14

Browse files
committed
fixing_tests_and_num_of_max_diff_vars
1 parent 8c61f7e commit b509c14

File tree

6 files changed

+110
-155
lines changed

6 files changed

+110
-155
lines changed
Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
#include "different_variables.h"
22

3-
void swap_two_int(int *a, int *b) {
3+
void swap_two_int_pointers(int *a, int *b) {
44
int t = *a;
55
*a = *b;
66
*b = t;
77
}
88

9-
void swap_four_int(int *a, int *b, int *c, int *d) {
10-
int t = *a;
11-
*a = *b;
12-
*b = t;
13-
int p = *c;
14-
*c = *d;
15-
*d = p;
16-
}
17-
18-
void swap_two_float(float *a, float *b) {
19-
float t = *a;
20-
*a = *b;
21-
*b = t;
9+
float max_of_two_float(float a, float b) {
10+
if (a > b)
11+
return a;
12+
return b;
2213
}
2314

24-
void swap_four_float(float *a, float *b, float *c, float *d) {
25-
float t = *a;
26-
*a = *b;
27-
*b = t;
28-
float f = *c;
29-
*c = *d;
30-
*d = f;
31-
}
32-
33-
void swap_two_int_two_float(int *a, int *b, float *c, float *d) {
34-
int t = *a;
35-
*a = *b;
36-
*b = t;
37-
float f = *c;
38-
*c = *d;
39-
*d = f;
40-
}
15+
int struct_test(struct easy_str a, struct easy_str b) {
16+
if (a.a == b.a) {
17+
return 1;
18+
}
19+
return -1;
20+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#ifndef SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
22
#define SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
33

4-
void swap_two_int(int *a, int *b);
4+
struct easy_str {
5+
int a;
6+
char b;
7+
};
58

6-
void swap_four_int(int *a, int *b, int *c, int *d);
9+
void swap_two_int_pointers(int *a, int *b);
710

8-
void swap_two_float(float *a, float *b);
11+
float max_of_two_float(float a, float b);
912

10-
void swap_four_float(float *a, float *b, float *c, float *d);
13+
int struct_test(struct easy_str a, struct easy_str b);
1114

12-
void swap_two_int_and_two_float(int *a, int *b, float *c, float *d);
13-
14-
#endif //SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
15+
#endif // SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H

server/src/printers/KleePrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ void KleePrinter::genParamsDeclarations(
394394
auto paramType =
395395
kleeParam.type.maybeJustPointer() ? kleeParam.type.baseTypeObj() : kleeParam.type;
396396
strKleeMakeSymbolic(paramType, kleeParam.name, param.name, !isArray);
397-
if(testGen->settingsContext.differentVariablesOfTheSameType && typesToNames[param.type.typeName()].size() <= 10){
397+
if(testGen->settingsContext.differentVariablesOfTheSameType && typesToNames[param.type.typeName()].size() <= 3){
398398
genConstraints(kleeParam, testMethod.name, typesToNames[param.type.typeName()]);}
399399
else {genConstraints(kleeParam, testMethod.name);}
400400
genTwoDimPointers(param, true);

server/test/framework/Server_Tests.cpp

Lines changed: 68 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,14 @@ namespace {
155155
simpleCheckerForPair(std::vector<std::string>(variables.begin() + 4, variables.end()), isInt, diffVars);
156156
}
157157

158-
void commonDifferentVariablesChecker(BaseTestGen &testGen, bool diffVars){
158+
void checkDifferentVariablesTrue_C(BaseTestGen &testGen){
159159
for (const auto &[methodName, methodDescription] :
160160
testGen.tests.at(different_variables_c).methods) {
161-
if (methodName == "swap_two_int") {
161+
if (methodName == "swap_two_int_pointers") {
162162
checkTestCasePredicates(
163163
methodDescription.testCases,
164164
std::vector<TestCasePredicate>(
165-
{ [diffVars](tests::Tests::MethodTestCase const &testCase) {
165+
{ [](tests::Tests::MethodTestCase const &testCase) {
166166
return commonSimpleChecker({testCase.paramValues[0]
167167
.view->getEntryValue(nullptr),
168168
testCase.paramPostValues[0]
@@ -171,39 +171,55 @@ namespace {
171171
.view->getEntryValue(nullptr),
172172
testCase.paramPostValues[1]
173173
.view->getEntryValue(nullptr)},
174-
true, diffVars) &&
174+
true, true) &&
175175
testCase.stdinValue == std::nullopt;
176176
} }),
177177
methodName);
178-
} else if (methodName == "swap_four_int") {
178+
} else if (methodName == "max_of_two_float") {
179179
checkTestCasePredicates(
180180
methodDescription.testCases,
181181
std::vector<TestCasePredicate>(
182-
{ [diffVars](tests::Tests::MethodTestCase const &testCase) {
183-
return commonSimpleChecker({testCase.paramValues[0]
184-
.view->getEntryValue(nullptr),
185-
testCase.paramPostValues[0]
186-
.view->getEntryValue(nullptr),
187-
testCase.paramValues[1]
188-
.view->getEntryValue(nullptr),
189-
testCase.paramPostValues[1]
190-
.view->getEntryValue(nullptr),
191-
testCase.paramValues[2]
192-
.view->getEntryValue(nullptr),
193-
testCase.paramPostValues[2]
194-
.view->getEntryValue(nullptr),
195-
testCase.paramValues[3]
196-
.view->getEntryValue(nullptr),
197-
testCase.paramPostValues[3]
198-
.view->getEntryValue(nullptr)},
199-
true, diffVars) &&
200-
testCase.stdinValue == std::nullopt;} }),
182+
{ [](tests::Tests::MethodTestCase const &testCase) {
183+
return stod(testCase.paramValues[0].view->getEntryValue(nullptr)) !=
184+
stod(testCase.paramValues[1].view->getEntryValue(nullptr)) &&
185+
stod(testCase.returnValue.view->getEntryValue(nullptr)) ==
186+
std::max(stod(testCase.paramValues[0].view->getEntryValue(nullptr)),
187+
stod(testCase.paramValues[1].view->getEntryValue(nullptr))) &&
188+
testCase.stdinValue == std::nullopt;
189+
},
190+
[](tests::Tests::MethodTestCase const &testCase) {
191+
return stod(testCase.paramValues[0].view->getEntryValue(nullptr)) !=
192+
stod(testCase.paramValues[1].view->getEntryValue(nullptr)) &&
193+
stod(testCase.returnValue.view->getEntryValue(nullptr)) ==
194+
std::max(stod(testCase.paramValues[0].view->getEntryValue(nullptr)),
195+
stod(testCase.paramValues[1].view->getEntryValue(nullptr))) &&
196+
testCase.stdinValue == std::nullopt;
197+
} }),
201198
methodName);
202-
} else if (methodName == "swap_two_float") {
199+
} else if (methodName == "struct_test") {
203200
checkTestCasePredicates(
204201
methodDescription.testCases,
205202
std::vector<TestCasePredicate>(
206-
{ [diffVars](tests::Tests::MethodTestCase const &testCase) {
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+
checkTestCasePredicates(
220+
methodDescription.testCases,
221+
std::vector<TestCasePredicate>(
222+
{ [](tests::Tests::MethodTestCase const &testCase) {
207223
return commonSimpleChecker({testCase.paramValues[0]
208224
.view->getEntryValue(nullptr),
209225
testCase.paramPostValues[0]
@@ -212,70 +228,47 @@ namespace {
212228
.view->getEntryValue(nullptr),
213229
testCase.paramPostValues[1]
214230
.view->getEntryValue(nullptr)},
215-
false, diffVars) &&
231+
true, false) &&
216232
testCase.stdinValue == std::nullopt;
217233
} }),
218234
methodName);
219-
} else if (methodName == "swap_four_float") {
235+
} else if (methodName == "max_of_two_float") {
220236
checkTestCasePredicates(
221237
methodDescription.testCases,
222238
std::vector<TestCasePredicate>(
223-
{ [diffVars](tests::Tests::MethodTestCase const &testCase) {
224-
return commonSimpleChecker({testCase.paramValues[0]
225-
.view->getEntryValue(nullptr),
226-
testCase.paramPostValues[0]
227-
.view->getEntryValue(nullptr),
228-
testCase.paramValues[1]
229-
.view->getEntryValue(nullptr),
230-
testCase.paramPostValues[1]
231-
.view->getEntryValue(nullptr),
232-
testCase.paramValues[2]
233-
.view->getEntryValue(nullptr),
234-
testCase.paramPostValues[2]
235-
.view->getEntryValue(nullptr),
236-
testCase.paramValues[3]
237-
.view->getEntryValue(nullptr),
238-
testCase.paramPostValues[3]
239-
.view->getEntryValue(nullptr)},
240-
false, diffVars) &&
241-
testCase.stdinValue == std::nullopt;} }),
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;
246+
},
247+
[](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;
254+
} }),
242255
methodName);
243-
} else if (methodName == "swap_two_int_two_float") {
256+
} else if (methodName == "struct_test") {
244257
checkTestCasePredicates(
245258
methodDescription.testCases,
246259
std::vector<TestCasePredicate>(
247-
{ [diffVars](tests::Tests::MethodTestCase const &testCase) {
248-
return commonSimpleChecker({testCase.paramValues[0]
249-
.view->getEntryValue(nullptr),
250-
testCase.paramPostValues[0]
251-
.view->getEntryValue(nullptr),
252-
testCase.paramValues[1]
253-
.view->getEntryValue(nullptr),
254-
testCase.paramPostValues[1]
255-
.view->getEntryValue(nullptr)},
256-
true, diffVars) &&
257-
commonSimpleChecker({testCase.paramValues[2]
258-
.view->getEntryValue(nullptr),
259-
testCase.paramPostValues[2]
260-
.view->getEntryValue(nullptr),
261-
testCase.paramValues[3]
262-
.view->getEntryValue(nullptr),
263-
testCase.paramPostValues[3]
264-
.view->getEntryValue(nullptr)},
265-
false, diffVars) &&
266-
testCase.stdinValue == std::nullopt;} }),
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+
} }),
267267
methodName);
268268
}
269269
}
270270
}
271271

272-
void checkDifferentVariablesTrue_C(BaseTestGen &testGen){
273-
commonDifferentVariablesChecker(testGen, true);
274-
}
275-
276-
void checkDifferentVariablesFalse_C(BaseTestGen &testGen){
277-
commonDifferentVariablesChecker(testGen, false);
278-
}
279272

280273
void checkBasicFunctions_C(BaseTestGen &testGen) {
281274
EXPECT_EQ(printer::TestsPrinter::needsMathHeader(testGen.tests.at(basic_functions_c)),
Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,20 @@
11
#include "different_variables.h"
22

3-
void swap_two_int(int *a, int *b) {
4-
int t = *a;
5-
*a = *b;
6-
*b = t;
7-
}
8-
9-
void swap_four_int(int *a, int *b, int *c, int *d) {
10-
int t = *a;
11-
*a = *b;
12-
*b = t;
13-
int p = *c;
14-
*c = *d;
15-
*d = p;
16-
}
17-
18-
void swap_two_float(float *a, float *b) {
19-
float t = *a;
20-
*a = *b;
21-
*b = t;
22-
}
23-
24-
void swap_four_float(float *a, float *b, float *c, float *d) {
25-
float t = *a;
26-
*a = *b;
27-
*b = t;
28-
float f = *c;
29-
*c = *d;
30-
*d = f;
31-
}
32-
33-
void swap_two_int_two_float(int *a, int *b, float *c, float *d) {
3+
void swap_two_int_pointers(int *a, int *b) {
344
int t = *a;
355
*a = *b;
366
*b = t;
37-
float f = *c;
38-
*c = *d;
39-
*d = f;
407
}
8+
9+
float max_of_two_float(float a, float b) {
10+
if (a > b)
11+
return a;
12+
return b;
13+
}
14+
15+
int struct_test(struct easy_str a, struct easy_str b) {
16+
if (a.a == b.a) {
17+
return 1;
18+
}
19+
return -1;
20+
}
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#ifndef SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
22
#define SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
33

4-
void swap_two_int(int *a, int *b);
4+
struct easy_str {
5+
int a;
6+
char b;
7+
};
58

6-
void swap_four_int(int *a, int *b, int *c, int *d);
9+
void swap_two_int_pointers(int *a, int *b);
710

8-
void swap_two_float(float *a, float *b);
11+
float max_of_two_float(float a, float b);
912

10-
void swap_four_float(float *a, float *b, float *c, float *d);
13+
int struct_test(struct easy_str a, struct easy_str b);
1114

12-
void swap_two_int_and_two_float(int *a, int *b, float *c, float *d);
13-
14-
#endif //SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H
15+
#endif // SIMPLE_TEST_PROJECT_DIFFERENT_VARIABLES_H

0 commit comments

Comments
 (0)