Skip to content

Commit 0edb0a0

Browse files
authored
Merge branch 'main' into yaml
2 parents 267ca18 + c8cec7f commit 0edb0a0

File tree

3 files changed

+27
-95
lines changed

3 files changed

+27
-95
lines changed

plugins/amazonq/codewhisperer/jetbrains-community/src/software/aws/toolkits/jetbrains/services/codewhisperer/util/CodeWhispererConstants.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ object CodeWhispererConstants {
148148

149149
object CrossFile {
150150
const val CHUNK_SIZE = 60
151-
const val NUMBER_OF_LINE_IN_CHUNK = 10
151+
const val NUMBER_OF_LINE_IN_CHUNK = 50
152152
const val NUMBER_OF_CHUNK_TO_FETCH = 3
153153
}
154154

plugins/amazonq/codewhisperer/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/codewhisperer/CodeWhispererUtilTest.kt

Lines changed: 20 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.junit.Test
1414
import software.amazon.awssdk.regions.Region
1515
import software.amazon.awssdk.services.codewhispererruntime.model.OptOutPreference
1616
import software.amazon.awssdk.services.ssooidc.SsoOidcClient
17+
import software.aws.toolkits.core.utils.test.aStringWithLineCount
1718
import software.aws.toolkits.jetbrains.core.MockClientManagerRule
1819
import software.aws.toolkits.jetbrains.core.credentials.LegacyManagedBearerSsoConnection
1920
import software.aws.toolkits.jetbrains.core.credentials.sono.Q_SCOPES
@@ -119,83 +120,45 @@ class CodeWhispererUtilTest {
119120

120121
@Test
121122
fun `toCodeChunk case_2`() {
122-
val psiFile = fixture.configureByText("Sample.java", codeSample33Lines)
123+
val fakeCodeWith210Lines = aStringWithLineCount(210)
124+
val psiFile = fixture.configureByText("Sample.java", fakeCodeWith210Lines)
123125

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

128-
assertThat(result).hasSize(5)
130+
// 210 / 50 + 2
131+
assertThat(result).hasSize(6)
129132

130133
// 0th
131-
assertThat(result[0].content).isEqualTo(
132-
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
133-
| int middle = low + ((high - low) / 2);
134-
""".trimMargin()
135-
)
134+
assertThat(result[0].content).isEqualTo(aStringWithLineCount(3))
136135
assertThat(result[0].path).isEqualTo("fake/path")
137-
assertThat(result[0].nextChunk).isEqualTo(result[1].content)
136+
assertThat(result[0].nextChunk).isEqualTo(aStringWithLineCount(50, start = 0))
138137

139138
// 1st
140-
assertThat(result[1].content).isEqualTo(
141-
"""|public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
142-
| int middle = low + ((high - low) / 2);
143-
|
144-
| if (high < low) {
145-
| return -1;
146-
| }
147-
|
148-
| if (key == sortedArray[middle]) {
149-
| return middle;
150-
| } else if (key < sortedArray[middle]) {
151-
""".trimMargin()
152-
)
139+
assertThat(result[1].content).isEqualTo(aStringWithLineCount(50, start = 0))
153140
assertThat(result[1].path).isEqualTo("fake/path")
154-
assertThat(result[1].nextChunk).isEqualTo(result[2].content)
141+
assertThat(result[1].nextChunk).isEqualTo(aStringWithLineCount(50, start = 50))
155142

156143
// 2nd
157-
assertThat(result[2].content).isEqualTo(
158-
"""| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
159-
| } else {
160-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
161-
| }
162-
|}
163-
|
164-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
165-
| int index = Integer.MAX_VALUE;
166-
|
167-
| while (low <= high) {
168-
""".trimMargin()
169-
)
144+
assertThat(result[2].content).isEqualTo(aStringWithLineCount(50, start = 50))
170145
assertThat(result[2].path).isEqualTo("fake/path")
171-
assertThat(result[2].nextChunk).isEqualTo(result[3].content)
146+
assertThat(result[2].nextChunk).isEqualTo(aStringWithLineCount(50, start = 100))
172147

173148
// 3rd
174-
assertThat(result[3].content).isEqualTo(
175-
"""| int mid = low + ((high - low) / 2);
176-
| if (sortedArray[mid] < key) {
177-
| low = mid + 1;
178-
| } else if (sortedArray[mid] > key) {
179-
| high = mid - 1;
180-
| } else if (sortedArray[mid] == key) {
181-
| index = mid;
182-
| break;
183-
| }
184-
| }
185-
""".trimMargin()
186-
)
149+
assertThat(result[3].content).isEqualTo(aStringWithLineCount(50, start = 100))
187150
assertThat(result[3].path).isEqualTo("fake/path")
188-
assertThat(result[3].nextChunk).isEqualTo(result[4].content)
151+
assertThat(result[3].nextChunk).isEqualTo(aStringWithLineCount(50, start = 150))
189152

190153
// 4th
191-
assertThat(result[4].content).isEqualTo(
192-
"""|
193-
| return index;
194-
|}
195-
""".trimMargin()
196-
)
154+
assertThat(result[4].content).isEqualTo(aStringWithLineCount(50, start = 150))
197155
assertThat(result[4].path).isEqualTo("fake/path")
198-
assertThat(result[4].nextChunk).isEqualTo(result[4].content)
156+
assertThat(result[4].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))
157+
158+
// 5th
159+
assertThat(result[5].content).isEqualTo(aStringWithLineCount(10, start = 200))
160+
assertThat(result[5].path).isEqualTo("fake/path")
161+
assertThat(result[5].nextChunk).isEqualTo(aStringWithLineCount(10, start = 200))
199162
}
200163

201164
@Test
@@ -230,40 +193,3 @@ class CodeWhispererUtilTest {
230193
assertThat(getTelemetryOptOutPreference()).isEqualTo(OptOutPreference.OPTOUT)
231194
}
232195
}
233-
234-
private val codeSample33Lines =
235-
"""public int runBinarySearchRecursively(int[] sortedArray, int key, int low, int high) {
236-
| int middle = low + ((high - low) / 2);
237-
|
238-
| if (high < low) {
239-
| return -1;
240-
| }
241-
|
242-
| if (key == sortedArray[middle]) {
243-
| return middle;
244-
| } else if (key < sortedArray[middle]) {
245-
| return runBinarySearchRecursively(sortedArray, key, low, middle - 1);
246-
| } else {
247-
| return runBinarySearchRecursively(sortedArray, key, middle + 1, high);
248-
| }
249-
|}
250-
|
251-
|public int runBinarySearchIteratively(int[] sortedArray, int key, int low, int high) {
252-
| int index = Integer.MAX_VALUE;
253-
|
254-
| while (low <= high) {
255-
| int mid = low + ((high - low) / 2);
256-
| if (sortedArray[mid] < key) {
257-
| low = mid + 1;
258-
| } else if (sortedArray[mid] > key) {
259-
| high = mid - 1;
260-
| } else if (sortedArray[mid] == key) {
261-
| index = mid;
262-
| break;
263-
| }
264-
| }
265-
|
266-
| return index;
267-
|}
268-
|
269-
""".trimMargin()

plugins/core/core/tst/software/aws/toolkits/core/utils/test/TestUtils.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import kotlin.random.Random
1111

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

14+
fun aStringWithLineCount(lineCount: Int, start: Int = 0): String = buildString {
15+
for (i in start until start + lineCount) {
16+
append("line$i\n")
17+
}
18+
}.trimEnd()
19+
1420
fun retryableAssert(
1521
timeout: Duration? = null,
1622
maxAttempts: Int? = null,

0 commit comments

Comments
 (0)