1
+ package changeMutableListValue
2
+
3
+ import org.junit.jupiter.api.Assertions.assertEquals
4
+ import org.junit.jupiter.api.Test
5
+
6
+ class ChangeMutableListValueUnitTest {
7
+
8
+ @Test
9
+ fun `changes mutable list value using set method` () {
10
+ val mutableList = mutableListOf (" kotlin" , " java" , " android" )
11
+ mutableList.set(1 , " swift" )
12
+ assertEquals(mutableListOf (" kotlin" , " swift" , " android" ), mutableList)
13
+ }
14
+
15
+ @Test
16
+ fun `changes mutable list value using indexed access operator` () {
17
+ val mutableList = mutableListOf (" kotlin" , " java" , " android" )
18
+ mutableList[1 ] = " swift"
19
+ assertEquals(mutableListOf (" kotlin" , " swift" , " android" ), mutableList)
20
+ }
21
+
22
+ @Test
23
+ fun `creates new list with updated value using the map method` () {
24
+ val mutableList = mutableListOf (" kotlin" , " java" , " android" )
25
+ val updatedList = mutableList.map { element ->
26
+ if (element == " java" ) {
27
+ " swift"
28
+ } else {
29
+ element
30
+ }
31
+ }
32
+ assertEquals(mutableListOf (" kotlin" , " swift" , " android" ), updatedList)
33
+ }
34
+
35
+ @Test
36
+ fun `changes mutable list value using the replace method` () {
37
+ val mutableList = mutableListOf (" kotlin" , " java" , " android" )
38
+ mutableList.replaceAll { if (it == " java" ) " swift" else it }
39
+ assertEquals(mutableListOf (" kotlin" , " swift" , " android" ), mutableList)
40
+ }
41
+ }
0 commit comments