class SplitTest

Public Instance Methods

test_split_with_argument() click to toggle source
# File activesupport/test/core_ext/array/grouping_test.rb, line 109
def test_split_with_argument
  a = [1, 2, 3, 4, 5]
  assert_equal [[1, 2], [4, 5]],  a.split(3)
  assert_equal [[1, 2, 3, 4, 5]], a.split(0)
  assert_equal [1, 2, 3, 4, 5], a
end
test_split_with_block() click to toggle source
# File activesupport/test/core_ext/array/grouping_test.rb, line 116
def test_split_with_block
  a = (1..10).to_a
  assert_equal [[1, 2], [4, 5], [7, 8], [10]], a.split { |i| i % 3 == 0 }
  assert_equal [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10], a
end
test_split_with_edge_values() click to toggle source
# File activesupport/test/core_ext/array/grouping_test.rb, line 122
def test_split_with_edge_values
  a = [1, 2, 3, 4, 5]
  assert_equal [[], [2, 3, 4, 5]],  a.split(1)
  assert_equal [[1, 2, 3, 4], []],  a.split(5)
  assert_equal [[], [2, 3, 4], []], a.split { |i| i == 1 || i == 5 }
  assert_equal [1, 2, 3, 4, 5], a
end
test_split_with_empty_array() click to toggle source
# File activesupport/test/core_ext/array/grouping_test.rb, line 105
def test_split_with_empty_array
  assert_equal [[]], [].split(0)
end
test_split_with_repeated_values() click to toggle source
# File activesupport/test/core_ext/array/grouping_test.rb, line 130
def test_split_with_repeated_values
  a = [1, 2, 3, 5, 5, 3, 4, 6, 2, 1, 3]
  assert_equal [[1, 2], [5, 5], [4, 6, 2, 1], []], a.split(3)
  assert_equal [[1, 2, 3], [], [3, 4, 6, 2, 1, 3]], a.split(5)
  assert_equal [[1, 2], [], [], [], [4, 6, 2, 1], []], a.split { |i| i == 3 || i == 5 }
  assert_equal [1, 2, 3, 5, 5, 3, 4, 6, 2, 1, 3], a
end