-
-
Save notahat/115405 to your computer and use it in GitHub Desktop.
This file contains 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 'test/unit' | |
require 'enumerator' | |
class Array | |
def in_chunks_of(size_of_chunks) | |
enum_slice(size_of_chunks).to_a | |
end | |
end | |
class TestArrayInChunks < Test::Unit::TestCase | |
def test_chunking_equal_to_size | |
assert_equal [1, 2].in_chunks_of(2), [[1, 2]] | |
end | |
def test_chunk_greater_than_size | |
assert_equal [1, 2].in_chunks_of(4), [[1, 2]] | |
end | |
def test_even_chunks | |
assert_equal [1, 2, 3, 4].in_chunks_of(2), [[1, 2], [3, 4]] | |
end | |
def test_more_than_two_chunks | |
assert_equal [1, 2, 3, 4, 5, 6].in_chunks_of(2), [[1, 2], [3, 4], [5, 6]] | |
end | |
def test_more_than_two_chunks_with_remainder | |
assert_equal [1, 2, 3, 4, 5, 6, 7].in_chunks_of(2), [[1, 2], [3, 4], [5, 6], [7]] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment