1
exercism fetch kotlin flatten-array

src/test/kotlin/FlattenerTest.kt

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import org.junit.Test
import org.junit.Ignore
import kotlin.test.assertEquals

class FlattenerTest {

    @Test
    fun flatListIsUnchanged() {
        val flatList = listOf(0, 1, 2)
        assertEquals(listOf(0, 1, 2), Flattener.flatten(flatList))
    }

    @Ignore
    @Test
    fun flattens2LevelNestedList() {
        val nestedList = listOf(1, listOf(2, 3, 4, 5, 6, 7), 8)
        assertEquals(listOf(1, 2, 3, 4, 5, 6, 7, 8), Flattener.flatten(nestedList))
    }

    @Ignore
    @Test
    fun flattens5LevelNestedList() {
        val nestedList = listOf(0, 2, listOf(listOf(2, 3), 8, 100, 4, listOf(listOf(listOf(50))), -2))
        assertEquals(listOf(0, 2, 2, 3, 8, 100, 4, 50, -2), Flattener.flatten(nestedList))
    }

    @Ignore
    @Test
    fun flattens6LevelNestedList() {
        val nestedList = listOf(1, listOf(2, listOf(listOf(3)), listOf(4, listOf(listOf(5))), 6, 7), 8)
        assertEquals(listOf(1, 2, 3, 4, 5, 6, 7, 8), Flattener.flatten(nestedList))
    }

    @Ignore
    @Test
    fun flattens6LevelNestedListWithNulls() {
        val nestedList = listOf(0, 2, listOf(listOf(2, 3), 8, listOf(listOf(100)), null, listOf(listOf(null))), -2)
        assertEquals(listOf(0, 2, 2, 3, 8, 100, -2), Flattener.flatten(nestedList))
    }

    @Ignore
    @Test
    fun allNullNestedListReturnsEmptyList() {
        val nestedList = listOf(null, listOf(listOf(listOf(null))), null, null, listOf(listOf(null, null), null), null)
        assertEquals(emptyList<Any>(), Flattener.flatten(nestedList))
    }

}