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.5.12 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.11 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.10 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.9 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.8 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.7 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.6 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.5 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.4 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.3 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.2 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.1 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.5.0 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.4.0 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.9 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.8 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.7 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.6 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.5 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt
trackler-2.0.3.4 tracks/kotlin/exercises/flatten-array/src/test/kotlin/FlattenerTest.kt