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.180 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.179 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.178 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.177 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.176 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.175 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.174 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.173 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.172 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.171 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.170 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.169 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.167 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.166 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.165 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.164 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.163 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.162 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.161 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.160 tracks/ruby/exercises/strain/strain_test.rb