[evaluation-plugin] take into account empty lookups in NotEmptyResultsRatio metric (LME-10)

GitOrigin-RevId: 839f9efad7adc00ea9c0990a42d9535ddbefdaa2
This commit is contained in:
Alexey Kalina
2024-07-18 11:21:40 +02:00
committed by intellij-monorepo-bot
parent e1881688ba
commit 18cc738337
2 changed files with 26 additions and 14 deletions

View File

@@ -19,7 +19,7 @@ class NotEmptyResultsRatio : Metric {
sessions
.flatMap { session -> session.lookups }
.forEach {
if (it.suggestions.all { suggestion -> suggestion.text.isBlank() }) {
if (it.suggestions.isEmpty() || it.suggestions.all { suggestion -> suggestion.text.isBlank() }) {
sample.add(0.0)
fileSample.add(0.0)
}

View File

@@ -9,9 +9,9 @@ class CodeGenerationMetricsTest {
@Test
fun `test correct results`() {
doTest(sessions = listOf(
session(result = "not-empty", withSyntaxErrors = false),
session(result = "not-empty-2", withSyntaxErrors = false),
session(result = "not-empty-3", withSyntaxErrors = false),
session(singleSuggestion(result = "not-empty"), withSyntaxErrors = false),
session(singleSuggestion(result = "not-empty-2"), withSyntaxErrors = false),
session(singleSuggestion(result = "not-empty-3"), withSyntaxErrors = false),
), listOf(
WithoutSyntaxErrorsSessionRatio() to 1.0,
NotEmptyResultsRatio() to 1.0
@@ -21,10 +21,10 @@ class CodeGenerationMetricsTest {
@Test
fun `test incorrect results`() {
doTest(sessions = listOf(
session(result = "", withSyntaxErrors = true),
session(result = "", withSyntaxErrors = true),
session(result = "with-errors", withSyntaxErrors = true),
session(result = "with-errors-2", withSyntaxErrors = true),
session(singleSuggestion(result = ""), withSyntaxErrors = true),
session(singleSuggestion(result = ""), withSyntaxErrors = true),
session(singleSuggestion(result = "with-errors"), withSyntaxErrors = true),
session(singleSuggestion(result = "with-errors-2"), withSyntaxErrors = true),
), listOf(
WithoutSyntaxErrorsSessionRatio() to 0.0,
NotEmptyResultsRatio() to 0.5
@@ -34,28 +34,40 @@ class CodeGenerationMetricsTest {
@Test
fun `test mixed results`() {
doTest(sessions = listOf(
session(result = "", withSyntaxErrors = true),
session(result = "not-empty", withSyntaxErrors = false),
session(result = "not-empty-2", withSyntaxErrors = false),
session(result = "with errors", withSyntaxErrors = true),
session(singleSuggestion(result = ""), withSyntaxErrors = true),
session(singleSuggestion(result = "not-empty"), withSyntaxErrors = false),
session(singleSuggestion(result = "not-empty-2"), withSyntaxErrors = false),
session(singleSuggestion(result = "with errors"), withSyntaxErrors = true),
), listOf(
WithoutSyntaxErrorsSessionRatio() to 0.5,
NotEmptyResultsRatio() to 0.75
))
}
@Test
fun `test session without suggestions`() {
doTest(sessions = listOf(
session(emptyList(), withSyntaxErrors = true),
), listOf(
WithoutSyntaxErrorsSessionRatio() to 0.0,
NotEmptyResultsRatio() to 0.0
))
}
private fun doTest(sessions: List<Session>, metric2expected: List<Pair<Metric, Double>>) {
for ((metric, expected) in metric2expected) {
Assertions.assertEquals(expected, metric.evaluate(sessions))
}
}
private fun session(result: String, withSyntaxErrors: Boolean): Session {
private fun singleSuggestion(result: String): List<Suggestion> = listOf(Suggestion(result, result, SuggestionSource.INTELLIJ))
private fun session(suggestions: List<Suggestion>, withSyntaxErrors: Boolean): Session {
val session = Session(0, "", 0, TokenProperties.UNKNOWN)
session.addLookup(Lookup(
prefix = "",
offset = 0,
suggestions = listOf(Suggestion(result, result, SuggestionSource.INTELLIJ)),
suggestions = suggestions,
latency = 0,
features = null,
selectedPosition = 0,