Skip to content

Commit

Permalink
Supported notApplicable for FixPlugin
Browse files Browse the repository at this point in the history
### What's done:
* supported not applicable counter for FixPlugin and empty result

It closes #1039
  • Loading branch information
nulls committed Aug 23, 2022
1 parent 528314e commit 5b6f52a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[versions]
kotlin = "1.7.10"
save-core = "0.3.3"
save-core = "0.4.0-SNAPSHOT"
ktor = "2.1.0"
okio = "3.2.0"
serialization = "1.4.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,10 @@ class SaveAgent(private val config: AgentConfiguration,
.unzip()
}

@Suppress("MAGIC_NUMBER", "MagicNumber")
private fun TestResultDebugInfo.getCountWarningsAsLong(getter: (CountWarnings) -> Int?) = this.debugInfo
?.countWarnings
?.let { getter(it) }
?.toLong()
?: 0L

private fun readExecutionReportFromFile(jsonFile: String): List<Report> {
val jsonFileContent = readFile(jsonFile).joinToString(separator = "")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.saveourtool.save.frontend.components.basic

import com.saveourtool.save.core.result.CountWarnings
import com.saveourtool.save.execution.ExecutionDto
import com.saveourtool.save.execution.ExecutionStatus
import com.saveourtool.save.frontend.externals.fontawesome.faRedo
Expand Down Expand Up @@ -96,13 +97,29 @@ internal class ExecutionStatisticsValues(executionDto: ExecutionDto?) {
?.let { calculateRate(it.passedTests, it.allTests) }
?: "0"
this.precisionRate = executionDto
?.let { calculateRate(it.matchedChecks, it.matchedChecks + it.unexpectedChecks) }
?.let {
if (allApplicable(it.matchedChecks, it.unexpectedChecks)) {
calculateRate(it.matchedChecks, it.matchedChecks + it.unexpectedChecks)
} else {
"N/A"
}
}
?: "0"
this.recallRate = executionDto
?.let { calculateRate(it.matchedChecks, it.matchedChecks + it.unmatchedChecks) }
?.let {
if (allApplicable(it.matchedChecks, it.unmatchedChecks)) {
calculateRate(it.matchedChecks, it.matchedChecks + it.unmatchedChecks)
} else {
"N/A"
}
}
?: "0"
}

private fun allApplicable(vararg values: Long): Boolean {
return values.all { !CountWarnings.isNotApplicable(it.toInt()) }
}

private fun calculateRate(numerator: Long, denominator: Long) = denominator.takeIf { it > 0 }
?.run { numerator.toDouble() / denominator }
?.let { it * 100 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.saveourtool.save.frontend.components.views

import com.saveourtool.save.agent.TestExecutionDto
import com.saveourtool.save.core.logging.describe
import com.saveourtool.save.core.result.CountWarnings
import com.saveourtool.save.domain.TestResultDebugInfo
import com.saveourtool.save.domain.TestResultStatus
import com.saveourtool.save.execution.ExecutionDto
Expand Down Expand Up @@ -130,14 +131,14 @@ class ExecutionView : AbstractView<ExecutionProps, ExecutionState>(false) {
column(id = "missing", header = "Missing", { unmatched }) {
Fragment.create {
td {
+"${it.value ?: ""}"
+formatCounter(it.value)
}
}
}
column(id = "matched", header = "Matched", { matched }) {
Fragment.create {
td {
+"${it.value ?: ""}"
+formatCounter(it.value)
}
}
}
Expand Down Expand Up @@ -299,6 +300,14 @@ class ExecutionView : AbstractView<ExecutionProps, ExecutionState>(false) {
}
)

private fun formatCounter(count: Long?): String = count?.let {
if (CountWarnings.isNotApplicable(it.toInt())) {
"N/A"
} else {
it.toString()
}
} ?: ""

init {
state.executionDto = null
state.filters = TestExecutionFilters.empty
Expand Down

0 comments on commit 5b6f52a

Please sign in to comment.