|
1 | 1 | package org.utbot.contest |
2 | 2 |
|
| 3 | +import java.io.File |
3 | 4 | import org.utbot.common.MutableMultiset |
4 | 5 | import org.utbot.common.mutableMultisetOf |
| 6 | +import org.utbot.framework.plugin.api.Instruction |
5 | 7 | import org.utbot.framework.plugin.api.UtError |
6 | | -import org.utbot.framework.plugin.api.Coverage |
7 | | -import java.io.File |
8 | 8 |
|
9 | 9 | private fun Double.format(digits: Int) = "%.${digits}f".format(this) |
10 | 10 |
|
@@ -55,11 +55,11 @@ class GlobalStats { |
55 | 55 | get() = statsForClasses.sumBy { it.concolicCoverage.getCoverageInfo(it.className).covered } |
56 | 56 |
|
57 | 57 | val totalInstructionsCount: Int |
58 | | - get() = statsForClasses.sumBy { it.coverage?.instructionsCount?.toInt() ?: 0 } |
| 58 | + get() = statsForClasses.sumBy { it.coverage.totalInstructions.toInt() } |
59 | 59 |
|
60 | 60 | val avgCoverage: Double |
61 | 61 | get() = statsForClasses |
62 | | - .filter { it.coverage?.instructionsCount?.let { cnt -> cnt != 0L } ?: false } |
| 62 | + .filter { it.coverage.totalInstructions != 0L } |
63 | 63 | .map { it.coverage.getCoverageInfo(it.className).run { if (total == 0) 0.0 else 100.0 * covered / total } } |
64 | 64 | .average() |
65 | 65 |
|
@@ -114,11 +114,11 @@ class StatsForClass(val className: String) { |
114 | 114 | val methodsWithAtLeastOneException: Int get() = statsForMethods.count { it.failReasons.isNotEmpty() } |
115 | 115 | val testcasesGenerated: Int get() = statsForMethods.sumBy { it.testsGeneratedCount } |
116 | 116 |
|
117 | | - var coverage: Coverage? = null |
118 | | - var fuzzedCoverage: Coverage? = null |
119 | | - var concolicCoverage: Coverage? = null |
| 117 | + var coverage = CoverageInstructionsSet() |
| 118 | + var fuzzedCoverage = CoverageInstructionsSet() |
| 119 | + var concolicCoverage = CoverageInstructionsSet() |
120 | 120 |
|
121 | | - private fun Coverage?.prettyInfo(): String = |
| 121 | + private fun CoverageInstructionsSet.prettyInfo(): String = |
122 | 122 | getCoverageInfo(className).run { "$covered/$total" } |
123 | 123 |
|
124 | 124 | override fun toString(): String = "\n<StatsForClass> :" + |
@@ -178,13 +178,18 @@ class FailReason(private val throwable: Throwable) { |
178 | 178 |
|
179 | 179 | } |
180 | 180 |
|
| 181 | +data class CoverageInstructionsSet( |
| 182 | + val coveredInstructions: MutableSet<Instruction> = mutableSetOf(), |
| 183 | + var totalInstructions: Long = 0 |
| 184 | +) |
| 185 | + |
181 | 186 | data class CoverageStatistic(val covered: Int, val total: Int) |
182 | 187 |
|
183 | | -private fun Coverage?.getCoverageInfo(className: String): CoverageStatistic = this?.run { |
| 188 | +private fun CoverageInstructionsSet?.getCoverageInfo(className: String): CoverageStatistic = this?.run { |
184 | 189 | CoverageStatistic( |
185 | 190 | coveredInstructions.filter { |
186 | 191 | instr -> instr.className.startsWith(className) |
187 | 192 | }.toSet().size, |
188 | | - instructionsCount?.toInt() ?: 0 |
| 193 | + totalInstructions.toInt() |
189 | 194 | ) |
190 | 195 | } ?: CoverageStatistic(covered = 0, total = 0) |
0 commit comments