File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
core-kotlin-modules/core-kotlin-strings-4/src/test/kotlin/com/baeldung/stringToChar Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com.baeldung.stringToChar
2
+
3
+ import org.junit.jupiter.api.Assertions.assertEquals
4
+ import org.junit.jupiter.api.Test
5
+
6
+ class StringToCharUnitTest {
7
+
8
+ @Test
9
+ fun `converts string to char using get method` (){
10
+ val str = " H"
11
+ val char = str.get(0 )
12
+
13
+ assertEquals(' H' , char)
14
+ }
15
+
16
+ @Test
17
+ fun `converts string to char using index operator method` (){
18
+ val str = " H"
19
+ val char = str[0 ]
20
+
21
+ assertEquals(' H' , char)
22
+ }
23
+
24
+ @Test
25
+ fun `converts string to char using single method` (){
26
+ val str = " H"
27
+ val char = str.single()
28
+
29
+ assertEquals(' H' , char)
30
+ }
31
+
32
+ @Test
33
+ fun `converts string to char using first method` (){
34
+ val str = " H"
35
+ val char = str.first()
36
+
37
+ assertEquals(' H' , char)
38
+ }
39
+
40
+ @Test
41
+ fun `converts string to char using toCharArray method` (){
42
+ val str = " H"
43
+ val charArray = str.toCharArray()
44
+ val char = charArray[0 ]
45
+
46
+ assertEquals(' H' , char)
47
+ }
48
+ }
You can’t perform that action at this time.
0 commit comments