blob: 69e939f2d959aea4df556cef2445b330f119139b [file] [log] [blame]
package kotlinx.coroutines.experimental.channels
import kotlinx.coroutines.experimental.*
import kotlin.coroutines.experimental.*
import kotlin.test.*
class SimpleSendReceiveTest : TestBase() {
@Test
fun testSimpleSendReceive() = runTest {
// Parametrized common test :(
TestChannelKind.values().forEach { kind -> testSendReceive(kind, 100) }
}
private suspend fun testSendReceive(kind: TestChannelKind, iterations: Int) {
val channel = kind.create()
launch(coroutineContext) {
repeat(iterations) { channel.send(it) }
channel.close()
}
var expected = 0
for (x in channel) {
if (!kind.isConflated) {
assertEquals(expected++, x)
} else {
assertTrue(x >= expected)
expected = x + 1
}
}
if (!kind.isConflated) {
assertEquals(iterations, expected)
}
}
}