Skip to content

Commit 71723a9

Browse files
authored
Fix parametrized test generation empty branch #683 (#682)
1 parent 6488a07 commit 71723a9

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/CgMethodTestSet.kt

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.utbot.framework.plugin.api.ExecutableId
55
import org.utbot.framework.plugin.api.FieldId
66
import org.utbot.framework.plugin.api.UtClusterInfo
77
import org.utbot.framework.plugin.api.UtExecution
8+
import org.utbot.framework.plugin.api.UtExecutionFailure
89
import org.utbot.framework.plugin.api.UtExecutionSuccess
910
import org.utbot.framework.plugin.api.UtMethodTestSet
1011
import org.utbot.framework.plugin.api.util.executableId
@@ -36,12 +37,19 @@ data class CgMethodTestSet private constructor(
3637
*/
3738
fun splitExecutionsByResult() : List<CgMethodTestSet> {
3839
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
39-
val executionsByResult: Map<ClassId, List<UtExecution>> =
40-
if (successfulExecutions.isNotEmpty()) {
41-
successfulExecutions.groupBy { (it.result as UtExecutionSuccess).model.classId }
42-
} else {
43-
mapOf(objectClassId to executions)
44-
}
40+
val failureExecutions = executions.filter { it.result is UtExecutionFailure }
41+
42+
val executionsByResult: MutableMap<ClassId, List<UtExecution>> =
43+
successfulExecutions
44+
.groupBy { (it.result as UtExecutionSuccess).model.classId }.toMutableMap()
45+
46+
// if we have failure executions, we add them to the first successful executions group
47+
val groupClassId = executionsByResult.keys.firstOrNull()
48+
if (groupClassId != null) {
49+
executionsByResult[groupClassId] = executionsByResult[groupClassId]!! + failureExecutions
50+
} else {
51+
executionsByResult[objectClassId] = failureExecutions
52+
}
4553

4654
return executionsByResult.map{ (_, executions) -> substituteExecutions(executions) }
4755
}
@@ -52,15 +60,8 @@ data class CgMethodTestSet private constructor(
5260
* A separate test set is created for each combination of modified statics.
5361
*/
5462
fun splitExecutionsByChangedStatics(): List<CgMethodTestSet> {
55-
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
5663
val executionsByStaticsUsage: Map<Set<FieldId>, List<UtExecution>> =
57-
if (successfulExecutions.isNotEmpty()) {
58-
successfulExecutions.groupBy {
59-
it.stateBefore.statics.keys
60-
}
61-
} else {
62-
mapOf(executions.first().stateBefore.statics.keys to executions)
63-
}
64+
executions.groupBy { it.stateBefore.statics.keys }
6465

6566
return executionsByStaticsUsage.map { (_, executions) -> substituteExecutions(executions) }
6667
}

utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree/CgMethodConstructor.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -783,7 +783,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
783783

784784
ifStatement(
785785
CgEqualTo(expectedNestedElement, nullLiteral()),
786-
trueBranch = { assertions[assertNull](actualNestedElement).toStatement() },
786+
trueBranch = { +assertions[assertNull](actualNestedElement).toStatement() },
787787
falseBranch = {
788788
floatingPointArraysDeepEquals(
789789
expectedArrayInfo.getNested(),
@@ -1055,7 +1055,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
10551055
actual.type.isPrimitive -> generateDeepEqualsAssertion(expected, actual)
10561056
else -> ifStatement(
10571057
CgEqualTo(expected, nullLiteral()),
1058-
trueBranch = { testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
1058+
trueBranch = { +testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
10591059
falseBranch = { generateDeepEqualsAssertion(expected, actual) }
10601060
)
10611061
}
@@ -1188,7 +1188,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
11881188
//may be a heuristic to select a model with minimal number of internal nulls should be used
11891189
val genericExecution = testSet.executions
11901190
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
1191-
?: testSet.executions.first()
1191+
?: testSet.executions
1192+
.firstOrNull { it.result is UtExecutionSuccess } ?: testSet.executions.first()
11921193

11931194
val statics = genericExecution.stateBefore.statics
11941195

0 commit comments

Comments
 (0)