Skip to content

Instantly share code, notes, and snippets.

@ronualdo
Created August 1, 2017 17:52
Show Gist options
  • Save ronualdo/66e2339a17a7c33229ca61bda977765e to your computer and use it in GitHub Desktop.
Save ronualdo/66e2339a17a7c33229ca61bda977765e to your computer and use it in GitHub Desktop.
defmodule FlattenTest do
use ExUnit.Case
doctest Flatten
test "flats an empty array" do
assert Flatten.flat([]) == []
end
test "flats an array with just one element" do
assert Flatten.flat([1]) == [1]
end
test "flats an array with two elements" do
assert Flatten.flat([1, 2]) == [1, 2]
end
test "flats an array that contains an empty array" do
assert Flatten.flat([[]]) == []
end
test "flats an array that contains numbers and an empty array" do
assert Flatten.flat([1, 2, [3], 4]) == [1, 2, 3, 4]
end
test "flats a number array that contains another number array" do
assert Flatten.flat([1, 2, [1, 2, 3], 4]) == [1, 2, 1, 2, 3, 4]
end
test "flats a number array with an empty multi index array" do
assert Flatten.flat([1, 2, 3, [[[]]], 4]) == [1, 2, 3, 4]
end
test "flats a number array with anothe multi index array" do
assert Flatten.flat([1, 2, [[[3]]], 4]) == [1, 2, 3, 4]
end
test "flats an array with number arrays" do
assert Flatten.flat([[1], [2, 3], [[4, 5, [[6]]]]]) == [1, 2, 3, 4, 5, 6]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment