Sha256: d8d2baaa030c88d6ade1aaa60ba38373034a0a7a43c882bb85912d167d0633cc

Contents?: true

Size: 1.84 KB

Versions: 188

Compression:

Stored size: 1.84 KB

Contents

require 'minitest/autorun'
require_relative 'strain'

class ArrayTest < Minitest::Test
  def test_empty_keep
    assert_equal [], [].keep { |e| e < 10 }
  end

  def test_keep_everything
    skip
    assert_equal [1, 2, 3], [1, 2, 3].keep { |e| e < 10 }
  end

  def test_keep_first_and_last
    skip
    assert_equal [1, 3], [1, 2, 3].keep(&:odd?)
  end

  def test_keep_neither_first_nor_last
    skip
    assert_equal [2, 4], [1, 2, 3, 4, 5].keep(&:even?)
  end

  def test_keep_strings
    skip
    words = %w(apple zebra banana zombies cherimoya zelot)
    result = words.keep { |word| word.start_with?('z') }
    assert_equal %w(zebra zombies zelot), result
  end

  def test_keep_arrays
    skip
    rows = [
      [1, 2, 3],
      [5, 5, 5],
      [5, 1, 2],
      [2, 1, 2],
      [1, 5, 2],
      [2, 2, 1],
      [1, 2, 5]
    ]
    result = rows.keep { |row| row.include?(5) }
    assert_equal [[5, 5, 5], [5, 1, 2], [1, 5, 2], [1, 2, 5]], result
  end

  def test_empty_discard
    skip
    assert_equal [], [].discard { |e| e < 10 }
  end

  def test_discard_nothing
    skip
    assert_equal [1, 2, 3], [1, 2, 3].discard { |e| e > 10 }
  end

  def test_discard_first_and_last
    skip
    assert_equal [2], [1, 2, 3].discard(&:odd?)
  end

  def test_discard_neither_first_nor_last
    skip
    assert_equal [1, 3, 5], [1, 2, 3, 4, 5].discard(&:even?)
  end

  def test_discard_strings
    skip
    words = %w(apple zebra banana zombies cherimoya zelot)
    result = words.discard { |word| word.start_with?('z') }
    assert_equal %w(apple banana cherimoya), result
  end

  def test_discard_arrays
    skip
    rows = [
      [1, 2, 3],
      [5, 5, 5],
      [5, 1, 2],
      [2, 1, 2],
      [1, 5, 2],
      [2, 2, 1],
      [1, 2, 5]
    ]
    result = rows.discard { |row| row.include?(5) }
    assert_equal [[1, 2, 3], [2, 1, 2], [2, 2, 1]], result
  end
end

Version data entries

188 entries across 188 versions & 1 rubygems

Version Path
trackler-2.2.1.78 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.77 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.76 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.75 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.74 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.73 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.72 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.71 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.70 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.69 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.68 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.67 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.66 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.65 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.64 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.63 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.62 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.61 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.60 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.59 tracks/ruby/exercises/strain/strain_test.rb