1
exercism fetch scala flatten-array

src/test/scala/FlattenArrayTest.scala

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
49
50
51
52
import org.scalatest.{Matchers, FunSuite}

/** @version 1.1.0 */
class FlattenArrayTest extends FunSuite with Matchers {

  test("no nesting") {
    FlattenArray.flatten(List(0, 1, 2)) should be(List(0, 1, 2))
  }

  test("flattens array with just integers present") {
    pending
    FlattenArray.flatten(List(1, List(2, 3, 4, 5, 6, 7), 8)) should be(
      List(1, 2, 3, 4, 5, 6, 7, 8))
  }

  test("5 level nesting") {
    pending
    FlattenArray.flatten(List(0,
                              2,
                              List(List(2, 3), 8, 100, 4, List(List(List(50)))),
                              -2)) should be(
      List(0, 2, 2, 3, 8, 100, 4, 50, -2))
  }

  test("6 level nesting") {
    pending
    FlattenArray.flatten(List(
      1,
      List(2, List(List(3)), List(4, List(List(5))), 6, 7),
      8)) should be(List(1, 2, 3, 4, 5, 6, 7, 8))
  }

  test("6 level nest list with null values") {
    pending
    FlattenArray.flatten(
      List(0,
           2,
           List(List(2, 3), 8, List(List(100)), null, List(List(null))),
           -2)) should be(List(0, 2, 2, 3, 8, 100, -2))
  }

  test("all values in nested list are null") {
    pending
    FlattenArray.flatten(
      List(null,
           List(List(List(null))),
           null,
           null,
           List(List(null, null), null),
           null)) should be(List())
  }
}