Sha256: 0c4a89833683afa0257e87b9d2402bc6c9637ac1a89daa808f039fffbcd759bf

Contents?: true

Size: 1.88 KB

Versions: 151

Compression:

Stored size: 1.88 KB

Contents

#!/usr/bin/env ruby
gem 'minitest', '>= 5.0.0'
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

151 entries across 151 versions & 1 rubygems

Version Path
trackler-2.1.0.7 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.6 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.5 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.4 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.3 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.2 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.1 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.1.0.0 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.55 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.54 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.53 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.52 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.51 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.50 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.49 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.48 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.47 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.46 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.45 tracks/ruby/exercises/strain/strain_test.rb
trackler-2.0.8.44 tracks/ruby/exercises/strain/strain_test.rb