11package org.utbot.contest
22
33import java.io.File
4+ import java.util.concurrent.ConcurrentSkipListSet
45import org.utbot.common.MutableMultiset
56import org.utbot.common.mutableMultisetOf
67import org.utbot.framework.plugin.api.Instruction
@@ -48,21 +49,21 @@ class GlobalStats {
4849 get() = statsForClasses.count { it.failedToCompile }
4950
5051 val coveredInstructions: Int
51- get() = statsForClasses.sumOf { it.coverage.getCoverageInfo(it.className ).covered }
52+ get() = statsForClasses.sumOf { it.coverage.getCoverageInfo(it.testedClassNames ).covered }
5253
5354 val coveredInstructionsByFuzzing: Int
54- get() = statsForClasses.sumOf { it.fuzzedCoverage.getCoverageInfo(it.className ).covered }
55+ get() = statsForClasses.sumOf { it.fuzzedCoverage.getCoverageInfo(it.testedClassNames ).covered }
5556
5657 val coveredInstructionsByConcolic: Int
57- get() = statsForClasses.sumOf { it.concolicCoverage.getCoverageInfo(it.className ).covered }
58+ get() = statsForClasses.sumOf { it.concolicCoverage.getCoverageInfo(it.testedClassNames ).covered }
5859
5960 val totalInstructions: Int
6061 get() = statsForClasses.sumOf { it.coverage.totalInstructions.toInt() }
6162
6263 val avgCoverage: Double
6364 get() = statsForClasses
6465 .filter { it.coverage.totalInstructions != 0L }
65- .map { it.coverage.getCoverageInfo(it.className ).run { 100.0 * covered / total } }
66+ .map { it.coverage.getCoverageInfo(it.testedClassNames ).run { 100.0 * covered / total } }
6667 .average().run {
6768 if (isNaN()) 0.0
6869 else this
@@ -108,7 +109,9 @@ class GlobalStats {
108109 avgCoverage.format(PRECISION ) + " %"
109110}
110111
111- class StatsForClass (val className : String ) {
112+ class StatsForClass {
113+ val testedClassNames: MutableSet <String > = ConcurrentSkipListSet ()
114+
112115 var methodsCount: Int = - 1
113116 val statsForMethods = mutableListOf<StatsForMethod >()
114117
@@ -123,8 +126,15 @@ class StatsForClass(val className: String) {
123126 var fuzzedCoverage = CoverageInstructionsSet ()
124127 var concolicCoverage = CoverageInstructionsSet ()
125128
129+ /* *
130+ * Add class [className] to respect coverage from this class.
131+ */
132+ fun addTestedClass (className : String ) {
133+ testedClassNames.add(className)
134+ }
135+
126136 private fun CoverageInstructionsSet.prettyInfo (): String =
127- getCoverageInfo(className ).run { " $covered /$total " }
137+ getCoverageInfo(testedClassNames ).run { " $covered /$total " }
128138
129139 override fun toString (): String = " \n <StatsForClass> :" +
130140 " \n\t canceled by timeout = $canceledByTimeout " +
@@ -191,12 +201,12 @@ data class CoverageInstructionsSet(
191201data class CoverageStatistic (val covered : Int , val total : Int )
192202
193203/* *
194- * Compute coverage of class named [className] with its anonymous, nested and inner classes .
204+ * Compute coverage of classes with names in [classNames] .
195205 */
196- private fun CoverageInstructionsSet?.getCoverageInfo (className : String ): CoverageStatistic = this ?.run {
206+ private fun CoverageInstructionsSet?.getCoverageInfo (classNames : Set < String > ): CoverageStatistic = this ?.run {
197207 CoverageStatistic (
198208 coveredInstructions.filter {
199- instr -> instr.className.startsWith( className)
209+ instr -> classNames.contains(instr. className)
200210 }.toSet().size,
201211 totalInstructions.toInt()
202212 )
0 commit comments