Skip to content

Commit ab1ffbc

Browse files
authored
cap the number of resources checked by the bulk test (#139)
1 parent 6bcebc7 commit ab1ffbc

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

src/commonTest/kotlin/co/pokeapi/pokekotlin/test/BulkTest.kt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ package co.pokeapi.pokekotlin.test
22

33
import co.pokeapi.pokekotlin.model.ResourceSummary
44
import co.pokeapi.pokekotlin.model.ResourceSummaryList
5+
import kotlin.math.min
56
import kotlin.test.Test
67
import kotlin.test.fail
78
import kotlinx.coroutines.test.runTest
89

9-
@IgnoreOnJvm // Should work on JVM but it's OOMing.
10+
private const val FIRST_N = 100
11+
private const val LAST_N = 100
12+
private const val MIDDLE_N = 100
13+
1014
class BulkTest {
1115

1216
private suspend fun testCase(cat: String, id: Int, getObject: suspend (Int) -> Any) {
@@ -24,7 +28,21 @@ class BulkTest {
2428
getObject: suspend (Int) -> O,
2529
) {
2630
val list = getList(0, getList(0, 0).count).results
27-
list.forEach { testCase(list[0].category, it.id, getObject) }
31+
val category = list[0].category
32+
33+
list.take(FIRST_N).forEach { testCase(category, it.id, getObject) }
34+
35+
if (list.size > FIRST_N + LAST_N) {
36+
val n = min(MIDDLE_N, list.size - FIRST_N - LAST_N)
37+
list.drop(FIRST_N).dropLast(LAST_N).shuffled().take(n).forEach {
38+
testCase(category, it.id, getObject)
39+
}
40+
}
41+
42+
if (list.size > FIRST_N) {
43+
val n = min(LAST_N, list.size - FIRST_N)
44+
list.takeLast(n).forEach { testCase(category, it.id, getObject) }
45+
}
2846
}
2947

3048
@Test

src/commonTest/kotlin/co/pokeapi/pokekotlin/test/Ignore.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/jsTest/kotlin/co/pokeapi/pokekotlin/test/Ignore.js.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/jvmTest/kotlin/co/pokeapi/pokekotlin/test/Ignore.jvm.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/nativeTest/kotlin/co/pokeapi/pokekotlin/test/Ignore.native.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/wasmJsTest/kotlin/co/pokeapi/pokekotlin/test/Ignore.wasmJs.kt

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)