Skip to content

Fix empty true branch & correct generic execution selection logic in parametrized test generation #683 #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.utbot.framework.plugin.api.ExecutableId
import org.utbot.framework.plugin.api.FieldId
import org.utbot.framework.plugin.api.UtClusterInfo
import org.utbot.framework.plugin.api.UtExecution
import org.utbot.framework.plugin.api.UtExecutionFailure
import org.utbot.framework.plugin.api.UtExecutionSuccess
import org.utbot.framework.plugin.api.UtMethodTestSet
import org.utbot.framework.plugin.api.util.executableId
Expand Down Expand Up @@ -36,12 +37,19 @@ data class CgMethodTestSet private constructor(
*/
fun splitExecutionsByResult() : List<CgMethodTestSet> {
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
val executionsByResult: Map<ClassId, List<UtExecution>> =
if (successfulExecutions.isNotEmpty()) {
successfulExecutions.groupBy { (it.result as UtExecutionSuccess).model.classId }
} else {
mapOf(objectClassId to executions)
}
val failureExecutions = executions.filter { it.result is UtExecutionFailure }

val executionsByResult: MutableMap<ClassId, List<UtExecution>> =
successfulExecutions
.groupBy { (it.result as UtExecutionSuccess).model.classId }.toMutableMap()

// if we have failure executions, we add them to the first successful executions group
val groupClassId = executionsByResult.keys.firstOrNull()
if (groupClassId != null) {
executionsByResult[groupClassId] = executionsByResult[groupClassId]!! + failureExecutions
} else {
executionsByResult[objectClassId] = failureExecutions
}

return executionsByResult.map{ (_, executions) -> substituteExecutions(executions) }
}
Expand All @@ -52,15 +60,8 @@ data class CgMethodTestSet private constructor(
* A separate test set is created for each combination of modified statics.
*/
fun splitExecutionsByChangedStatics(): List<CgMethodTestSet> {
val successfulExecutions = executions.filter { it.result is UtExecutionSuccess }
val executionsByStaticsUsage: Map<Set<FieldId>, List<UtExecution>> =
if (successfulExecutions.isNotEmpty()) {
successfulExecutions.groupBy {
it.stateBefore.statics.keys
}
} else {
mapOf(executions.first().stateBefore.statics.keys to executions)
}
executions.groupBy { it.stateBefore.statics.keys }

return executionsByStaticsUsage.map { (_, executions) -> substituteExecutions(executions) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c

ifStatement(
CgEqualTo(expectedNestedElement, nullLiteral()),
trueBranch = { assertions[assertNull](actualNestedElement).toStatement() },
trueBranch = { +assertions[assertNull](actualNestedElement).toStatement() },
falseBranch = {
floatingPointArraysDeepEquals(
expectedArrayInfo.getNested(),
Expand Down Expand Up @@ -1055,7 +1055,7 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
actual.type.isPrimitive -> generateDeepEqualsAssertion(expected, actual)
else -> ifStatement(
CgEqualTo(expected, nullLiteral()),
trueBranch = { testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
trueBranch = { +testFrameworkManager.assertions[testFramework.assertNull](actual).toStatement() },
falseBranch = { generateDeepEqualsAssertion(expected, actual) }
)
}
Expand Down Expand Up @@ -1188,7 +1188,8 @@ internal class CgMethodConstructor(val context: CgContext) : CgContextOwner by c
//may be a heuristic to select a model with minimal number of internal nulls should be used
val genericExecution = testSet.executions
.firstOrNull { it.result is UtExecutionSuccess && (it.result as UtExecutionSuccess).model !is UtNullModel }
?: testSet.executions.first()
?: testSet.executions
.firstOrNull { it.result is UtExecutionSuccess } ?: testSet.executions.first()

val statics = genericExecution.stateBefore.statics

Expand Down