Skip to content

Commit fa1cf9f

Browse files
authored
Fix minimization missing last empty branch (#2288)
1 parent af3aab5 commit fa1cf9f

File tree

1 file changed

+6
-10
lines changed
  • utbot-framework/src/main/kotlin/org/utbot/framework/minimization

1 file changed

+6
-10
lines changed

utbot-framework/src/main/kotlin/org/utbot/framework/minimization/Minimization.kt

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ private fun groupByBranchInstructions(
9292
executions: List<UtExecution>,
9393
branchInstructionsNumber: Int
9494
): Collection<List<UtExecution>> {
95-
val instructionToPossibleNextInstructions = mutableMapOf<Long, MutableSet<Long>>()
95+
val instructionToPossibleNextInstructions = mutableMapOf<Long, MutableSet<Long?>>()
9696

9797
for (execution in executions) {
9898
execution.coverage?.let { coverage ->
9999
val coveredInstructionIds = coverage.coveredInstructions.map { it.id }
100-
for (i in 0 until coveredInstructionIds.size - 1) {
100+
for (i in coveredInstructionIds.indices) {
101101
instructionToPossibleNextInstructions
102102
.getOrPut(coveredInstructionIds[i]) { mutableSetOf() }
103-
.add(coveredInstructionIds[i + 1])
103+
.add(coveredInstructionIds.getOrNull(i + 1))
104104
}
105105
}
106106
}
@@ -153,7 +153,7 @@ private fun <T : Any> groupExecutionsByTestSuite(
153153
*/
154154
private fun buildMapping(executions: List<UtExecution>): Pair<Map<Int, List<Int>>, Map<Int, Int>> {
155155
// (inst1, instr2) -> edge id --- edge represents as a pair of instructions, which are connected by this edge
156-
val allCoveredEdges = mutableMapOf<Pair<Long, Long>, Int>()
156+
val allCoveredEdges = mutableMapOf<Pair<Long, Long?>, Int>()
157157
val thrownExceptions = mutableMapOf<String, Long>()
158158
val mapping = mutableMapOf<Int, List<Int>>()
159159
val executionToPriorityMapping = mutableMapOf<Int, Int>()
@@ -167,14 +167,10 @@ private fun buildMapping(executions: List<UtExecution>): Pair<Map<Int, List<Int>
167167
execution.result,
168168
thrownExceptions
169169
).let { instructions ->
170-
for (i in 0 until instructions.size - 1) {
171-
allCoveredEdges.putIfAbsent(instructions[i] to instructions[i + 1], allCoveredEdges.size)
170+
val edges = instructions.indices.map { i ->
171+
allCoveredEdges.getOrPut(instructions[i] to instructions.getOrNull(i + 1)) { allCoveredEdges.size }
172172
}
173173

174-
val edges = mutableListOf<Int>()
175-
for (i in 0 until instructions.size - 1) {
176-
edges += allCoveredEdges[instructions[i] to instructions[i + 1]]!!
177-
}
178174
mapping[idx] = edges
179175
executionToPriorityMapping[idx] = execution.getExecutionPriority()
180176
}

0 commit comments

Comments
 (0)