Created
March 1, 2017 10:05
-
-
Save gabrielbidula/599e555ed589bc2c20df654dab42cc6d to your computer and use it in GitHub Desktop.
flatten an array of arbitrarily nested arrays of integers into a flat array of integers - test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
require_relative 'nice_flatten' | |
class NiceFlattenTest < Minitest::Test | |
def test_flattens_an_array_of_nested_arrays_into_a_flat_array | |
flattened_array = [[1, 2, [3]], 4].flatten | |
assert_equal [1, 2, 3, 4], flattened_array | |
end | |
def test_flattens_another_array_of_nested_arrays_into_a_flat_array | |
flattened_array = [[1, 2, [3]], 4, [5], [6, 7, [8]]].flatten | |
assert_equal [1, 2, 3, 4, 5, 6, 7, 8], flattened_array | |
end | |
def test_flattens_an_empty_array | |
flattened_array = [].flatten | |
assert_equal [], flattened_array | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple tests using minitest