forked from Kotlin/kotlinx.coroutines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Flow.any, Flow.all, Flow.none
See Kotlin#4212
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
kotlinx-coroutines-core/common/test/flow/operators/BooleanTerminationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package kotlinx.coroutines.flow | ||
|
||
import kotlinx.coroutines.testing.* | ||
import kotlin.test.* | ||
|
||
class BooleanTerminationTest : TestBase() { | ||
@Test | ||
fun testAnyNominal() = runTest { | ||
val flow = flow { | ||
emit(1) | ||
emit(2) | ||
} | ||
|
||
assertTrue(flow.any { it > 0 }) | ||
assertTrue(flow.any { it % 2 == 0 }) | ||
assertFalse(flow.any { it > 5 }) | ||
} | ||
|
||
@Test | ||
fun testAnyEmpty() = runTest { | ||
assertFalse(emptyFlow<Int>().any { it > 0 }) | ||
} | ||
|
||
@Test | ||
fun testAllNominal() = runTest { | ||
val flow = flow { | ||
emit(1) | ||
emit(2) | ||
} | ||
|
||
assertTrue(flow.all { it > 0 }) | ||
assertFalse(flow.all { it % 2 == 0 }) | ||
assertFalse(flow.all { it > 5 }) | ||
} | ||
|
||
@Test | ||
fun testAllEmpty() = runTest { | ||
assertTrue(emptyFlow<Int>().all { it > 0 }) | ||
} | ||
|
||
@Test | ||
fun testNoneNominal() = runTest { | ||
val flow = flow { | ||
emit(1) | ||
emit(2) | ||
} | ||
|
||
assertFalse(flow.none { it > 0 }) | ||
assertFalse(flow.none { it % 2 == 0 }) | ||
assertTrue(flow.none { it > 5 }) | ||
} | ||
|
||
@Test | ||
fun testNoneEmpty() = runTest { | ||
assertTrue(emptyFlow<Int>().none { it > 0 }) | ||
} | ||
|
||
} |