Sha256: e0462b0470a688ae43adafd16e49fb1799fc27650ffc8412ae637c892bfabc7b

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

# -*- coding: utf-8 -*-
require "sixarm_ruby_ramp_test"

class EnumerableNItemsTest < Minitest::Test

  ITEMS = ['a','b','c']

  def test_nitems?
    assert_equal(true,  ITEMS.nitems?(0){|x| x < 'a'})
    assert_equal(false, ITEMS.nitems?(1){|x| x < 'a'})
    assert_equal(false, ITEMS.nitems?(2){|x| x < 'a'})
    assert_equal(false, ITEMS.nitems?(0){|x| x < 'b'})
    assert_equal(true,  ITEMS.nitems?(1){|x| x < 'b'})
    assert_equal(false, ITEMS.nitems?(2){|x| x < 'b'})
    assert_equal(false, ITEMS.nitems?(0){|x| x < 'c'})
    assert_equal(false, ITEMS.nitems?(1){|x| x < 'c'})
    assert_equal(true,  ITEMS.nitems?(2){|x| x < 'c'})
  end


  def test_nitems_while
    assert_equal(0,ITEMS.nitems_while{|x| x < 'a' },'< a')
    assert_equal(1,ITEMS.nitems_while{|x| x < 'b' },'< b')
    assert_equal(2,ITEMS.nitems_while{|x| x < 'c' },'< c')
    assert_equal(3,ITEMS.nitems_while{|x| x < 'd' },'< d')
    assert_equal(3,ITEMS.nitems_while{|x| x < 'e' },'< e')
  end


  def test_nitems_until
    assert_equal(0,ITEMS.nitems_until{|x| x == 'a' },'a')
    assert_equal(1,ITEMS.nitems_until{|x| x == 'b' },'b')
    assert_equal(2,ITEMS.nitems_until{|x| x == 'c' },'c')
    assert_equal(3,ITEMS.nitems_until{|x| x == 'd' },'d')
    assert_equal(3,ITEMS.nitems_until{|x| x == 'e' },'e')
  end


  def test_nitems_with_index
    assert_equal(0,ITEMS.nitems_with_index{|x,i| i < 0 },'i < 0')
    assert_equal(1,ITEMS.nitems_with_index{|x,i| i < 1 },'i < 1')
    assert_equal(2,ITEMS.nitems_with_index{|x,i| i < 2 },'i < 2')
    assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 3 },'i < 3')
    assert_equal(3,ITEMS.nitems_with_index{|x,i| i < 4 },'i < 4')
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sixarm_ruby_ramp-5.0.2 test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb
sixarm_ruby_ramp-5.0.1 test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb
sixarm_ruby_ramp-5.0.0 test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb
sixarm_ruby_ramp-4.2.7 test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb
sixarm_ruby_ramp-4.2.5 test/sixarm_ruby_ramp_test/enumerable/nitems_test.rb