Skip to content

Commit 42290f8

Browse files
committed
Fix parametrized test generation empty branch
1 parent c447c0b commit 42290f8

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
10501050
actual.type.isPrimitive -> generateDeepEqualsAssertion(expected, actual)
10511051
else -> ifStatement(
10521052
CgEqualTo(expected, nullLiteral()),
1053-
trueBranch = { testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
1053+
trueBranch = { +testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
10541054
falseBranch = { generateDeepEqualsAssertion(expected, actual) }
10551055
)
10561056
}
@@ -1183,7 +1183,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
11831183
//may be a heuristic to select a model with minimal number of internal nulls should be used
11841184
val genericExecution = testSet.executions
11851185
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
1186-
?: testSet.executions.first()
1186+
?: testSet.executions
1187+
.firstOrNull { it.result is UtExecutionSuccess } ?: testSet.executions.first()
11871188

11881189
val statics = genericExecution.stateBefore.statics
11891190

0 commit comments

Comments
 (0)