Kotlin Ternary Conditional Operator (#8427)

* Kotlin Ternary Conditional Operator

* moved to package

Co-authored-by: Sam Millington <s.j.millington@hotmail.co.uk>
This commit is contained in:
petershatunov 2020-01-02 01:20:44 +03:00 committed by Sam Millington
parent 48e8676d77
commit 9c32b6c3d8
2 changed files with 30 additions and 0 deletions

View File

@ -5,4 +5,10 @@ This module contains articles about core Kotlin.
### Relevant articles: ### Relevant articles:
- [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions) - [Kotlin Scope Functions](https://www.baeldung.com/kotlin-scope-functions)
- [Kotlin Annotations](https://www.baeldung.com/kotlin-annotations)
- [Split a List into Parts in Kotlin](https://www.baeldung.com/kotlin-split-list-into-parts)
- [String Comparison in Kotlin](https://www.baeldung.com/kotlin-string-comparison)
- [Guide to JVM Platform Annotations in Kotlin](https://www.baeldung.com/kotlin-jvm-annotations)
- [Finding an Element in a List Using Kotlin](https://www.baeldung.com/kotlin-finding-element-in-list)
- [Kotlin Ternary Conditional Operator](https://www.baeldung.com/kotlin-ternary-conditional-operator)
- More articles: [[<-- prev]](/core-kotlin) - More articles: [[<-- prev]](/core-kotlin)

View File

@ -0,0 +1,24 @@
package com.baeldung.ternary
import org.junit.Test
import kotlin.test.assertEquals
class TernaryOperatorTest {
@Test
fun `using If`() {
val a = true
val result = if (a) "yes" else "no"
assertEquals("yes", result)
}
@Test
fun `using When`() {
val a = true
val result = when(a) {
true -> "yes"
false -> "no"
}
assertEquals("yes", result)
}
}