1
exercism fetch elixir flatten-array

flatten_array_test.exs

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
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("flatten_array.exs", __DIR__)
end

ExUnit.start
ExUnit.configure exclude: :pending, trace: true

defmodule FlattenArrayTest do
  use ExUnit.Case

  test "returns original list if there is nothing to flatten" do
    assert FlattenArray.flatten([1, 2, 3]) ==  [1, 2, 3]
  end

  @tag :pending
  test "flattens an empty nested list" do
    assert FlattenArray.flatten([[]]) ==  []
  end

  @tag :pending
  test "flattens a nested list" do
    assert FlattenArray.flatten([1,[2,[3],4],5,[6,[7,8]]]) == [1, 2, 3, 4, 5, 6, 7, 8]
  end

  @tag :pending
  test "removes nil from list" do
    assert FlattenArray.flatten([1, nil, 2]) ==  [1, 2]
  end

  @tag :pending
  test "removes nil from a nested list" do
    assert FlattenArray.flatten([1, [2, nil, 4], 5]) ==  [1, 2, 4, 5]
  end

  @tag :pending
  test "returns an empty list if all values in nested list are nil" do
    assert FlattenArray.flatten([nil, [nil], [nil, [nil]]]) ==  []
  end
end