Skip to content

Commit 261b124

Browse files
[KTLN-703] Kotlin Equivalent of Java's equalsIgnoreCase (#784)
* added unit tests * fixed unit tests * fixed unit tests * fixed code
1 parent d8745b4 commit 261b124

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.baeldung.equalsIgnoreCaseInKotlin
2+
3+
import org.junit.jupiter.api.Assertions.assertFalse
4+
import org.junit.jupiter.api.Assertions.assertTrue
5+
import org.junit.jupiter.api.Test
6+
7+
class EqualsIgnoreCaseInKotlinUnitTest {
8+
9+
@Test
10+
fun `test string case insensitive comparison using equals and lowercase methods`() {
11+
val result1 = "Hello".lowercase() == "hello".lowercase()
12+
val result2 = "Hello".lowercase() == "world".lowercase()
13+
14+
assertTrue(result1)
15+
assertFalse(result2)
16+
}
17+
18+
@Test
19+
fun `test string case insensitive comparison using equals methods`() {
20+
val result1 = "Hello".equals("hello", true)
21+
val result2 = "Hello".equals("world", true)
22+
23+
assertTrue(result1)
24+
assertFalse(result2)
25+
}
26+
27+
@Test
28+
fun `test string case insensitive comparison using compareTo method`() {
29+
val result1 = "Hello".compareTo("hello", true) == 0
30+
val result2 = "Hello".compareTo("world", true) == 0
31+
32+
assertTrue(result1)
33+
assertFalse(result2)
34+
}
35+
}

0 commit comments

Comments
 (0)