Skip to content

Commit 6effdcf

Browse files
committed
Add test for parallel iteration over generated sequence
1 parent 81bb04a commit 6effdcf

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

kotlinx-coroutines-generate/src/test/kotlin/GenerateTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,17 @@ class GenerateTest {
134134
sharedVar = -2
135135
assertTrue(assertFails { iterator.hasNext() } is IllegalStateException)
136136
}
137+
138+
@Test
139+
fun testParallelIteration() {
140+
var inc = 0
141+
val result = generate<Int> {
142+
for (i in 1..3) {
143+
inc++
144+
yield(inc * i)
145+
}
146+
}
147+
148+
assertEquals(listOf(Pair(1, 2), Pair(6, 8), Pair(15, 18)), result.zip(result).toList())
149+
}
137150
}

0 commit comments

Comments
 (0)