Skip to content

Instantly share code, notes, and snippets.

@shaicoleman
Created April 27, 2015 06:57
Show Gist options
  • Save shaicoleman/458facb8717e665bda2c to your computer and use it in GitHub Desktop.
Save shaicoleman/458facb8717e665bda2c to your computer and use it in GitHub Desktop.
require 'minitest/autorun'
require './flatten'
describe 'Flatten' do
it 'invalid parameter' do
assert_raises(ArgumentError) do
ArrayUtils.flatten(1)
end
end
it 'empty array' do
ArrayUtils.flatten([]).must_equal []
end
it 'not nested' do
ArrayUtils.flatten([1, 2, 3]).must_equal [1, 2, 3]
end
it 'single nested item' do
ArrayUtils.flatten([-1]).must_equal [-1]
end
it 'different types' do
ArrayUtils.flatten(['1', 2, 3.0, [], { x: 'y' }, nil, [1..3], :test]).must_equal \
['1', 2, 3, { x: 'y' }, nil, 1..3, :test]
end
it 'multiple nested' do
ArrayUtils.flatten([1,[2,[3]],[4,5]]).must_equal [1,2,3,4,5]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment