Skip to content

Commit

Permalink
test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewyuq committed Oct 10, 2024
1 parent 68880af commit 5a466c4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ class CodeWhispererClientAdaptorTest {
@Test
fun `sendTelemetryEvent for userModification respects telemetry optin status`() {
sendTelemetryEventOptOutCheckHelper {
sut.sendUserModificationTelemetry(aString(), aString(), aProgrammingLanguage(), aString(), 0.0)
sut.sendUserModificationTelemetry(aString(), aString(), aProgrammingLanguage(), aString(), 0, 0)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeCove
import software.aws.toolkits.jetbrains.services.codewhisperer.telemetry.CodeWhispererCodeCoverageTracker
import software.aws.toolkits.jetbrains.services.codewhisperer.toolwindow.CodeWhispererCodeReferenceManager
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants.TOTAL_SECONDS_IN_MINUTE
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererUtil.getUnmodifiedAcceptedCharsCount
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CrossFileStrategy
import software.aws.toolkits.jetbrains.services.telemetry.NoOpPublisher
import software.aws.toolkits.jetbrains.services.telemetry.TelemetryService
Expand Down Expand Up @@ -376,28 +377,6 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
assertThat(sut.totalTokensSize).isEqualTo(0)
}

@Test
fun `test when rangeMarker is not vaild, acceptedToken will not be updated`() {
// when user delete whole recommendation, rangeMarker will be isValid = false
val rangeMarkerMock: RangeMarker = mock()
whenever(rangeMarkerMock.isValid).thenReturn(false)
sut = spy(
TestCodePercentageTracker(
project,
TOTAL_SECONDS_IN_MINUTE,
CodeWhispererPython.INSTANCE,
mutableListOf(rangeMarkerMock),
)
) {
onGeneric { getUnmodifiedAcceptedCharsCount(any(), any()) } doReturn 100
}

sut.activateTrackerIfNotActive()
sut.forceTrackerFlush()

verify(sut, Times(0)).getUnmodifiedAcceptedCharsCount(any(), any())
}

@Test
fun `test flush() will call emitTelemetry automatically schedule next call`() {
sut = spy(
Expand Down Expand Up @@ -465,48 +444,47 @@ internal class CodeWhispererCodeCoverageTrackerTestPython : CodeWhispererCodeCov
}

@Test
fun `test getAcceptedTokensDelta()`() {
val tracker = TestCodePercentageTracker(project, TOTAL_SECONDS_IN_MINUTE, CodeWhispererPython.INSTANCE)
fun `test getUnmodifiedAcceptedCharsCount()`() {
var originalRecommendation = "foo"
var modifiedRecommendation = "fou"
var delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo(2)
var unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo(2)

originalRecommendation = "foo"
modifiedRecommendation = "f11111oo"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo(3)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo(3)

originalRecommendation = "foo"
modifiedRecommendation = "fo"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo(2)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo(2)

originalRecommendation = "helloworld"
modifiedRecommendation = "HelloWorld"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo("helloworld".length - 2)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo("helloworld".length - 2)

originalRecommendation = "helloworld"
modifiedRecommendation = "World"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo("helloworld".length - "hello".length - 1)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo("helloworld".length - "hello".length - 1)

originalRecommendation = "CodeWhisperer"
modifiedRecommendation = "CODE"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo(1)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo(1)

originalRecommendation = "CodeWhisperer"
modifiedRecommendation = "codewhispererISBEST"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo("CodeWhisperer".length - 2)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo("CodeWhisperer".length - 2)

val pythonCommentAddedByUser = "\"\"\"we don't count this comment as generated by CodeWhisperer\"\"\"\n"
originalRecommendation = "x, y):\n\treturn x + y"
modifiedRecommendation = "x, y):\n$pythonCommentAddedByUser\treturn x + y"
delta = tracker.getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(delta).isEqualTo(originalRecommendation.length)
unmodifiedCharsCount = getUnmodifiedAcceptedCharsCount(originalRecommendation, modifiedRecommendation)
assertThat(unmodifiedCharsCount).isEqualTo(originalRecommendation.length)
}

@Test
Expand Down

0 comments on commit 5a466c4

Please sign in to comment.