Sha256: 1ee3319c039b2caa47fc0d527ad330bfb52e44da702aeaab39090470017601e7

Contents?: true

Size: 1.63 KB

Versions: 89

Compression:

Stored size: 1.63 KB

Contents

import org.junit.Test
import kotlin.test.assertEquals

class FlattenerTest {

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

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

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

    @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))
    }

    @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))
    }

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

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

}

Version data entries

89 entries across 89 versions & 1 rubygems

Version Path
trackler-2.0.6.33 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.32 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.31 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.30 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.29 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.28 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.27 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.26 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.25 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.24 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.23 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.22 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.21 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.20 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.19 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.18 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.17 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.16 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.15 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.6.14 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt