Skip to content

Commit c4cf84e

Browse files
committed
Result class improved
1 parent 7e4957a commit c4cf84e

File tree

2 files changed

+25
-8
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/framework/codegen/model/constructor/tree
  • utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api

2 files changed

+25
-8
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,39 @@ data class CgMethodTestSet private constructor(
122122
* unique result model [ClassId] in each subset.
123123
*/
124124
fun splitExecutionsByResult() : List<CgMethodTestSet> {
125+
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
125126
val executionsByResult: Map<ClassId, List<UtExecution>> =
126-
if (executions.any { it.result is UtExecutionSuccess })
127-
executions
128-
.filter { it.result is UtExecutionSuccess }
129-
.groupBy { (it.result as UtExecutionSuccess).model.classId }
130-
else {
127+
if (successfulExecutions.any()) {
128+
successfulExecutions.groupBy { (it.result as UtExecutionSuccess).model.classId }
129+
} else {
131130
mapOf(objectClassId to executions)
132131
}
133132

134133
return executionsByResult.map{ (_, executions) -> substituteExecutions(executions) }
135134
}
136135

136+
/**
137+
* Finds a [ClassId] of all result models in executions.
138+
*
139+
* Tries to find an unique result type in testSets or
140+
* gets executable return type.
141+
*/
142+
fun resultType(): ClassId {
143+
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
144+
return if (successfulExecutions.any()) {
145+
successfulExecutions
146+
.map { (it.result as UtExecutionSuccess).model.classId }
147+
.distinct()
148+
.singleOrNull()
149+
?: executableId.returnType
150+
} else {
151+
executableId.returnType
152+
}
153+
}
154+
137155
private fun substituteExecutions(newExecutions: List<UtExecution>): CgMethodTestSet =
138156
this.copy().apply { executions = newExecutions }
157+
139158
}
140159

141160

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,9 +1265,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
12651265
currentMethodParameters[CgParameterKind.Argument(index)] = argument.parameter
12661266
}
12671267

1268-
val method = currentExecutable!!
1269-
val expectedResultClassId = wrapTypeIfRequired(method.returnType)
1270-
1268+
val expectedResultClassId = wrapTypeIfRequired(testSet.resultType())
12711269
if (expectedResultClassId != voidClassId) {
12721270
val wrappedType = wrapIfPrimitive(expectedResultClassId)
12731271
//We are required to wrap the type of expected result if it is primitive

0 commit comments

Comments
 (0)