Skip to content

Commit 4bc3566

Browse files
committed
Refactor after review
1 parent 6ce7c0f commit 4bc3566

File tree

3 files changed

+61
-58
lines changed

3 files changed

+61
-58
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ fun main(args: Array<String>) {
146146
fuzzingRatio = 0.1,
147147
classpathString,
148148
runFromEstimator = false,
149-
methodNameFilter = null,
150-
expectedExceptions = ExpectedExceptionsForClass()
149+
expectedExceptions = ExpectedExceptionsForClass(),
150+
methodNameFilter = null
151151
)
152152
println("${ContestMessage.READY}")
153153
}
@@ -180,8 +180,8 @@ fun runGeneration(
180180
fuzzingRatio: Double,
181181
classpathString: String,
182182
runFromEstimator: Boolean,
183-
methodNameFilter: String? = null, // For debug purposes you can specify method name
184-
expectedExceptions: ExpectedExceptionsForClass
183+
expectedExceptions: ExpectedExceptionsForClass,
184+
methodNameFilter: String? = null // For debug purposes you can specify method name
185185
): StatsForClass = runBlocking {
186186
val testsByMethod: MutableMap<ExecutableId, MutableList<UtExecution>> = mutableMapOf()
187187
val currentContext = utContext

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

Lines changed: 3 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ enum class Tool {
148148
fuzzingRatio,
149149
project.sootClasspathString,
150150
runFromEstimator = true,
151-
methodNameFilter,
152-
expectedExceptions
151+
expectedExceptions,
152+
methodNameFilter
153153
)
154154
} catch (e: CancellationException) {
155155
logger.info { "[$classFqn] finished with CancellationException" }
@@ -410,7 +410,7 @@ fun runEstimator(
410410
val project = ProjectToEstimate(
411411
name,
412412
classesFQN,
413-
projectToExpectedExceptions[name]!!,
413+
projectToExpectedExceptions.getValue(name),
414414
File(classpathDir, name).listFiles()!!.filter { it.toString().endsWith("jar") },
415415
testCandidatesDir,
416416
unzippedJars
@@ -535,57 +535,6 @@ private fun classNamesByJar(jar: File): List<String> {
535535
.toList()
536536
}
537537

538-
class ExpectedExceptionsForMethod(
539-
val exceptionNames: List<String>
540-
)
541-
542-
class ExpectedExceptionsForClass {
543-
544-
private val byMethodName: MutableMap<String, ExpectedExceptionsForMethod> =
545-
mutableMapOf()
546-
547-
fun getForMethod(methodName: String): ExpectedExceptionsForMethod =
548-
byMethodName[methodName] ?: ExpectedExceptionsForMethod(listOf())
549-
550-
fun setForMethod(methodName: String, exceptionNames: List<String>) {
551-
byMethodName[methodName] = ExpectedExceptionsForMethod(exceptionNames)
552-
}
553-
}
554-
555-
class ExpectedExceptionsForProject {
556-
557-
private val byClassName: MutableMap<String, ExpectedExceptionsForClass> =
558-
mutableMapOf()
559-
560-
fun getForClass(className: String): ExpectedExceptionsForClass =
561-
byClassName[className] ?: ExpectedExceptionsForClass()
562-
563-
fun setForClass(className: String, methodName: String, exceptionNames: List<String>) {
564-
val forClass = byClassName.getOrPut(className) { ExpectedExceptionsForClass() }
565-
forClass.setForMethod(methodName, exceptionNames)
566-
}
567-
}
568-
569-
fun parseExceptionsFile(exceptionsDescriptionFile: File): ExpectedExceptionsForProject {
570-
if (!exceptionsDescriptionFile.exists()) {
571-
return ExpectedExceptionsForProject()
572-
}
573-
574-
val forProject = ExpectedExceptionsForProject()
575-
for (methodDescription in exceptionsDescriptionFile.readLines()) {
576-
val methodFqn = methodDescription.substringBefore(':').trim()
577-
val classFqn = methodFqn.substringBeforeLast('.')
578-
val methodName = methodFqn.substringAfterLast('.')
579-
val exceptionFqns = methodDescription.substringAfter(':')
580-
.split(' ')
581-
.map { it.trim() }
582-
.filter { it.isNotBlank() }
583-
forProject.setForClass(classFqn, methodName, exceptionFqns)
584-
}
585-
586-
return forProject
587-
}
588-
589538
class ProjectToEstimate(
590539
val name: String,
591540
val classFQNs: List<String>,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.utbot.contest
2+
3+
import java.io.File
4+
5+
class ExpectedExceptionsForMethod(
6+
val exceptionNames: List<String>
7+
)
8+
9+
class ExpectedExceptionsForClass {
10+
11+
private val byMethodName: MutableMap<String, ExpectedExceptionsForMethod> =
12+
mutableMapOf()
13+
14+
fun getForMethod(methodName: String): ExpectedExceptionsForMethod =
15+
byMethodName[methodName] ?: ExpectedExceptionsForMethod(listOf())
16+
17+
fun setForMethod(methodName: String, exceptionNames: List<String>) {
18+
byMethodName[methodName] = ExpectedExceptionsForMethod(exceptionNames)
19+
}
20+
}
21+
22+
class ExpectedExceptionsForProject {
23+
24+
private val byClassName: MutableMap<String, ExpectedExceptionsForClass> =
25+
mutableMapOf()
26+
27+
fun getForClass(className: String): ExpectedExceptionsForClass =
28+
byClassName[className] ?: ExpectedExceptionsForClass()
29+
30+
fun setForClass(className: String, methodName: String, exceptionNames: List<String>) {
31+
val forClass = byClassName.getOrPut(className) { ExpectedExceptionsForClass() }
32+
forClass.setForMethod(methodName, exceptionNames)
33+
}
34+
}
35+
36+
fun parseExceptionsFile(exceptionsDescriptionFile: File): ExpectedExceptionsForProject {
37+
if (!exceptionsDescriptionFile.exists()) {
38+
return ExpectedExceptionsForProject()
39+
}
40+
41+
val forProject = ExpectedExceptionsForProject()
42+
for (methodDescription in exceptionsDescriptionFile.readLines()) {
43+
val methodFqn = methodDescription.substringBefore(':').trim()
44+
val classFqn = methodFqn.substringBeforeLast('.')
45+
val methodName = methodFqn.substringAfterLast('.')
46+
val exceptionFqns = methodDescription.substringAfter(':')
47+
.split(' ')
48+
.map { it.trim() }
49+
.filter { it.isNotBlank() }
50+
forProject.setForClass(classFqn, methodName, exceptionFqns)
51+
}
52+
53+
return forProject
54+
}

0 commit comments

Comments
 (0)