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.159 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.158 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.157 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.156 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.155 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.154 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.153 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.152 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.151 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.150 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.149 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.148 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.147 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.146 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.145 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.144 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.143 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.142 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.141 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.2.1.140 tracks/ruby/exercises/strain/strain_test.rb