Skip to content

Fix duplication of nested testclasses #779 #780

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 24, 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 @@ -20,18 +20,18 @@ data class TestClassModel(
val class2methodTestSets = testSets.groupBy { it.executableId.classId }

val classesWithMethodsUnderTest = testSets
.distinctBy { it.executableId.classId }
.map { it.executableId.classId }
.distinct()

// For each class stores list of its "direct" nested classes
val class2nestedClasses = mutableMapOf<ClassId, MutableList<ClassId>>()
val class2nestedClasses = mutableMapOf<ClassId, MutableSet<ClassId>>()

for (classId in classesWithMethodsUnderTest) {
var currentClass = classId
var enclosingClass = currentClass.enclosingClass
// while we haven't reached the top of nested class hierarchy or the main class under test
while (enclosingClass != null && currentClass != classUnderTest) {
class2nestedClasses.getOrPut(enclosingClass) { mutableListOf() } += currentClass
class2nestedClasses.getOrPut(enclosingClass) { mutableSetOf() } += currentClass
currentClass = enclosingClass
enclosingClass = enclosingClass.enclosingClass
}
Expand All @@ -42,7 +42,7 @@ data class TestClassModel(
private fun constructRecursively(
clazz: ClassId,
class2methodTestSets: Map<ClassId, List<CgMethodTestSet>>,
class2nestedClasses: Map<ClassId, List<ClassId>>
class2nestedClasses: Map<ClassId, Set<ClassId>>
): TestClassModel {
val currentNestedClasses = class2nestedClasses.getOrDefault(clazz, listOf())
val currentMethodTestSets = class2methodTestSets.getOrDefault(clazz, listOf())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import org.utbot.framework.codegen.model.tree.CgTestMethod
import org.utbot.framework.codegen.model.tree.CgThisInstance
import org.utbot.framework.codegen.model.tree.CgValue
import org.utbot.framework.codegen.model.tree.CgVariable
import org.utbot.framework.codegen.model.util.createTestClassName
import java.util.IdentityHashMap
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.PersistentMap
Expand Down Expand Up @@ -449,7 +448,7 @@ internal data class CgContext(

override val outerMostTestClass: ClassId by lazy {
val packagePrefix = if (testClassPackageName.isNotEmpty()) "$testClassPackageName." else ""
val simpleName = testClassCustomName ?: "${createTestClassName(classUnderTest.name)}Test"
val simpleName = testClassCustomName ?: "${classUnderTest.simpleName}Test"
val name = "$packagePrefix$simpleName"
BuiltinClassId(
name = name,
Expand Down