Skip to content

Commit 09c8479

Browse files
committed
Fix for summarization when list of parameters was the same for every case
1 parent 73fc824 commit 09c8479

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

utbot-fuzzers/src/main/kotlin/org/utbot/fuzzing/JavaLanguage.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,39 +49,32 @@ suspend fun runJavaFuzzing(
4949
exec: suspend (thisInstance: FuzzedValue?, description: FuzzedDescription, values: List<FuzzedValue>) -> BaseFeedback<Trie.Node<Instruction>, FuzzedType, FuzzedValue>
5050
) {
5151
val classUnderTest = methodUnderTest.classId
52-
val thisInstance = with(methodUnderTest) {
53-
if (!isStatic && !isConstructor) {
54-
classUnderTest
55-
} else {
56-
null
57-
}
58-
}
5952
val name = methodUnderTest.classId.simpleName + "." + methodUnderTest.name
6053
val returnType = methodUnderTest.returnType
61-
val parameters = listOfNotNull(thisInstance) + methodUnderTest.parameters
54+
val parameters = methodUnderTest.parameters
6255

6356
/**
6457
* To fuzz this instance the class of it is added into head of parameters list.
6558
* Done for compatibility with old fuzzer logic and should be reworked more robust way.
6659
*/
67-
fun createFuzzedMethodDescription(thisInstance: ClassId?) = FuzzedMethodDescription(
68-
name, returnType, parameters, constants
60+
fun createFuzzedMethodDescription(self: ClassId?) = FuzzedMethodDescription(
61+
name, returnType, listOfNotNull(self) + parameters, constants
6962
).apply {
7063
compilableName = if (!methodUnderTest.isConstructor) methodUnderTest.name else null
7164
className = classUnderTest.simpleName
7265
packageName = classUnderTest.packageName
7366
parameterNameMap = { index ->
7467
when {
75-
thisInstance != null && index == 0 -> "this"
76-
thisInstance != null -> names.getOrNull(index - 1)
68+
self != null && index == 0 -> "this"
69+
self != null -> names.getOrNull(index - 1)
7770
else -> names.getOrNull(index)
7871
}
7972
}
8073
fuzzerType = {
8174
try {
8275
when {
83-
thisInstance != null && it == 0 -> toFuzzerType(methodUnderTest.executable.declaringClass)
84-
thisInstance != null -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it - 1])
76+
self != null && it == 0 -> toFuzzerType(methodUnderTest.executable.declaringClass)
77+
self != null -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it - 1])
8578
else -> toFuzzerType(methodUnderTest.executable.genericParameterTypes[it])
8679
}
8780
} catch (_: Throwable) {
@@ -91,12 +84,15 @@ suspend fun runJavaFuzzing(
9184
shouldMock = mock
9285
}
9386

87+
val thisInstance = with(methodUnderTest) {
88+
if (!isStatic && !isConstructor) { classUnderTest } else { null }
89+
}
9490
val tracer = Trie(Instruction::id)
9591
val descriptionWithOptionalThisInstance = FuzzedDescription(createFuzzedMethodDescription(thisInstance), tracer)
9692
val descriptionWithOnlyParameters = FuzzedDescription(createFuzzedMethodDescription(null), tracer)
97-
BaseFuzzing(providers) { d, t ->
93+
BaseFuzzing(providers) { _, t ->
9894
if (thisInstance == null) {
99-
exec(null, d, t)
95+
exec(null, descriptionWithOnlyParameters, t)
10096
} else {
10197
exec(t.first(), descriptionWithOnlyParameters, t.drop(1))
10298
}

utbot-fuzzing/src/test/kotlin/org/utbot/fuzzing/samples/Integers.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
@SuppressWarnings({"unused", "RedundantIfStatement"})
44
public class Integers {
55

6+
public byte biting(byte a, byte b, boolean s) {
7+
if (s) {
8+
return a;
9+
} else {
10+
return b;
11+
}
12+
}
13+
614
// should cover 100%
715
public static void diff(int a) {
816
a = Math.abs(a);

0 commit comments

Comments
 (0)