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:
parent
48e8676d77
commit
9c32b6c3d8
|
@ -5,4 +5,10 @@ This module contains articles about core Kotlin.
|
|||
### Relevant articles:
|
||||
|
||||
- [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)
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue