Skip to content

Commit 5435ce3

Browse files
Introduce minimization in ContestEstimator #1651 (#1664)
1 parent 29718ea commit 5435ce3

File tree

1 file changed

+5
-6
lines changed
  • utbot-junit-contest/src/main/kotlin/org/utbot/contest

1 file changed

+5
-6
lines changed

utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import kotlinx.coroutines.runBlocking
6161
import kotlinx.coroutines.withTimeoutOrNull
6262
import kotlinx.coroutines.yield
6363
import org.utbot.framework.codegen.services.language.CgLanguageAssistant
64+
import org.utbot.framework.minimization.minimizeExecutions
6465
import org.utbot.framework.plugin.api.util.isSynthetic
6566

6667
internal const val junitVersion = 4
@@ -180,10 +181,7 @@ fun runGeneration(
180181
runFromEstimator: Boolean,
181182
methodNameFilter: String? = null // For debug purposes you can specify method name
182183
): StatsForClass = runBlocking {
183-
184-
185-
186-
val testSets: MutableList<UtMethodTestSet> = mutableListOf()
184+
val testsByMethod: MutableMap<ExecutableId, MutableList<UtExecution>> = mutableMapOf()
187185
val currentContext = utContext
188186

189187
val timeBudgetMs = timeLimitSec * 1000
@@ -340,8 +338,7 @@ fun runGeneration(
340338
}
341339
statsForClass.testedClassNames.add(className)
342340

343-
//TODO: it is a strange hack to create fake test case for one [UtResult]
344-
testSets.add(UtMethodTestSet(method, listOf(result)))
341+
testsByMethod.getOrPut(method) { mutableListOf() } += result
345342
} catch (e: Throwable) {
346343
//Here we need isolation
347344
logger.error(e) { "Code generation failed" }
@@ -393,6 +390,8 @@ fun runGeneration(
393390
}
394391
cancellator.cancel()
395392

393+
val testSets = testsByMethod.map { (method, executions) -> UtMethodTestSet(method, minimizeExecutions(executions)) }
394+
396395
logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") {
397396
writeTestClass(cut, codeGenerator.generateAsString(testSets))
398397
}

0 commit comments

Comments
 (0)