Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ object CodeWhispererConstants {
}
object CrossFile {
const val CHUNK_SIZE = 60
const val NUMBER_OF_LINE_IN_CHUNK = 10
const val NUMBER_OF_LINE_IN_CHUNK = 50
const val NUMBER_OF_CHUNK_TO_FETCH = 3
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import org.junit.Test
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.codewhispererruntime.model.OptOutPreference
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
import software.aws.toolkits.core.utils.test.aStringWithLineCount
import software.aws.toolkits.jetbrains.core.MockClientManagerRule
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
Expand Down Expand Up @@ -119,83 +120,45 @@ class CodeWhispererUtilTest {

@Test
fun `toCodeChunk case_2`() {
val psiFile = fixture.configureByText("Sample.java", codeSample33Lines)
val fakeCodeWith210Lines = aStringWithLineCount(210)
val psiFile = fixture.configureByText("Sample.java", fakeCodeWith210Lines)

val result = runBlocking {
psiFile.virtualFile.toCodeChunk("fake/path")
}.toList()

assertThat(result).hasSize(5)
// 210 / 50 + 2
assertThat(result).hasSize(6)

// 0th
assertThat(result[0].content).isEqualTo(
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
| int middle = low + ((high - low) / 2);
""".trimMargin()
)
assertThat(result[0].content).isEqualTo(aStringWithLineCount(3))
assertThat(result[0].path).isEqualTo("fake/path")
assertThat(result[0].nextChunk).isEqualTo(result[1].content)
assertThat(result[0].nextChunk).isEqualTo(aStringWithLineCount(50, start = 0))

// 1st
assertThat(result[1].content).isEqualTo(
"""|public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
| int middle = low + ((high - low) / 2);
|
| if (high < low) {
| return -1;
| }
|
| if (key == sortedArray[middle]) {
| return middle;
| } else if (key < sortedArray[middle]) {
""".trimMargin()
)
assertThat(result[1].content).isEqualTo(aStringWithLineCount(50, start = 0))
assertThat(result[1].path).isEqualTo("fake/path")
assertThat(result[1].nextChunk).isEqualTo(result[2].content)
assertThat(result[1].nextChunk).isEqualTo(aStringWithLineCount(50, start = 50))

// 2nd
assertThat(result[2].content).isEqualTo(
"""| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
| } else {
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
| }
|}
|
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
| int index = Integer.MAX_VALUE;
|
| while (low <= high) {
""".trimMargin()
)
assertThat(result[2].content).isEqualTo(aStringWithLineCount(50, start = 50))
assertThat(result[2].path).isEqualTo("fake/path")
assertThat(result[2].nextChunk).isEqualTo(result[3].content)
assertThat(result[2].nextChunk).isEqualTo(aStringWithLineCount(50, start = 100))

// 3rd
assertThat(result[3].content).isEqualTo(
"""| int mid = low + ((high - low) / 2);
| if (sortedArray[mid] < key) {
| low = mid + 1;
| } else if (sortedArray[mid] > key) {
| high = mid - 1;
| } else if (sortedArray[mid] == key) {
| index = mid;
| break;
| }
| }
""".trimMargin()
)
assertThat(result[3].content).isEqualTo(aStringWithLineCount(50, start = 100))
assertThat(result[3].path).isEqualTo("fake/path")
assertThat(result[3].nextChunk).isEqualTo(result[4].content)
assertThat(result[3].nextChunk).isEqualTo(aStringWithLineCount(50, start = 150))

// 4th
assertThat(result[4].content).isEqualTo(
"""|
| return index;
|}
""".trimMargin()
)
assertThat(result[4].content).isEqualTo(aStringWithLineCount(50, start = 150))
assertThat(result[4].path).isEqualTo("fake/path")
assertThat(result[4].nextChunk).isEqualTo(result[4].content)
assertThat(result[4].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))

// 5th
assertThat(result[5].content).isEqualTo(aStringWithLineCount(10, start = 200))
assertThat(result[5].path).isEqualTo("fake/path")
assertThat(result[5].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))
}

@Test
Expand Down Expand Up @@ -230,40 +193,3 @@ class CodeWhispererUtilTest {
assertThat(getTelemetryOptOutPreference()).isEqualTo(OptOutPreference.OPTOUT)
}
}

private val codeSample33Lines =
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
| int middle = low + ((high - low) / 2);
|
| if (high < low) {
| return -1;
| }
|
| if (key == sortedArray[middle]) {
| return middle;
| } else if (key < sortedArray[middle]) {
| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
| } else {
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
| }
|}
|
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
| int index = Integer.MAX_VALUE;
|
| while (low <= high) {
| int mid = low + ((high - low) / 2);
| if (sortedArray[mid] < key) {
| low = mid + 1;
| } else if (sortedArray[mid] > key) {
| high = mid - 1;
| } else if (sortedArray[mid] == key) {
| index = mid;
| break;
| }
| }
|
| return index;
|}
|
""".trimMargin()
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import kotlin.random.Random

fun aString(length: Int = Random.nextInt(5, 30)): String = UUID.randomUUID().toString().substring(length)

fun aStringWithLineCount(lineCount: Int, start: Int = 0): String = buildString {
for (i in start until start + lineCount) {
append("line$i\n")
}
}.trimEnd()

fun retryableAssert(
timeout: Duration? = null,
maxAttempts: Int? = null,
Expand Down
Loading