File tree Expand file tree Collapse file tree
src/test/kotlin/com/baeldung/ternary Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,4 +5,10 @@ This module contains articles about core Kotlin.
55### Relevant articles:
66
77- [ Kotlin Scope Functions] ( https://www.baeldung.com/kotlin-scope-functions )
8+ - [ Kotlin Annotations] ( https://www.baeldung.com/kotlin-annotations )
9+ - [ Split a List into Parts in Kotlin] ( https://www.baeldung.com/kotlin-split-list-into-parts )
10+ - [ String Comparison in Kotlin] ( https://www.baeldung.com/kotlin-string-comparison )
11+ - [ Guide to JVM Platform Annotations in Kotlin] ( https://www.baeldung.com/kotlin-jvm-annotations )
12+ - [ Finding an Element in a List Using Kotlin] ( https://www.baeldung.com/kotlin-finding-element-in-list )
13+ - [ Kotlin Ternary Conditional Operator] ( https://www.baeldung.com/kotlin-ternary-conditional-operator )
814- More articles: [[ <-- prev]] ( /core-kotlin )
Original file line number Diff line number Diff line change 1+ package com.baeldung.ternary
2+
3+ import org.junit.Test
4+ import kotlin.test.assertEquals
5+
6+ class TernaryOperatorTest {
7+
8+ @Test
9+ fun `using If` () {
10+ val a = true
11+ val result = if (a) " yes" else " no"
12+ assertEquals(" yes" , result)
13+ }
14+
15+ @Test
16+ fun `using When` () {
17+ val a = true
18+ val result = when (a) {
19+ true -> " yes"
20+ false -> " no"
21+ }
22+ assertEquals(" yes" , result)
23+ }
24+ }
You can’t perform that action at this time.
0 commit comments