Skip to content

Instantly share code, notes, and snippets.

@gabrielbidula
Created March 1, 2017 10:05
Show Gist options
  • Save gabrielbidula/599e555ed589bc2c20df654dab42cc6d to your computer and use it in GitHub Desktop.
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
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
@gabrielbidula
Copy link
Author

simple tests using minitest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment