PageRenderTime 143ms CodeModel.GetById 41ms app.highlight 45ms RepoModel.GetById 55ms app.codeStats 0ms

/vendor/gems/facets-2.4.5/test/core/array/test_indexable.rb

https://bitbucket.org/mediashelf/fedora-migrator
Ruby | 118 lines | 77 code | 18 blank | 23 comment | 0 complexity | e4afc3a2c0600d2a447067a4448fa688 MD5 | raw file
  1require 'facets/array/indexable.rb'
  2require 'test/unit'
  3
  4class TestArray < Test::Unit::TestCase
  5
  6  #def test_op_mod
  7  #  a = [:A,:B,:C]
  8  #  assert_equal( a[1], a/1 )
  9  #  assert_equal( :B, a/1 )
 10  #end
 11  #
 12  #def test_op_div
 13  #  a = [:A,:B,:C]
 14  #  assert_equal( a[1], a/1 )
 15  #  assert_equal( :B, a/1 )
 16  #end
 17
 18  def test_head
 19    a = [1,2,3,4,5]
 20    assert_equal( [1], a.head )
 21  end
 22
 23  def test_tail
 24    a = [1,2,3,4,5]
 25    assert_equal( [2,3,4,5], a.tail )
 26  end
 27
 28  def test_foot
 29    a = [1,2,3,4,5]
 30    assert_equal( [5], a.foot )
 31  end
 32
 33  def test_body
 34    a = [1,2,3,4,5]
 35    assert_equal( [1,2,3,4], a.body )
 36  end
 37
 38  def test_mid
 39    a = [1,2,3,4,5]
 40    b = [1,2,3,4,5,6]
 41    assert_equal( 3, a.mid )
 42    assert_equal( 4, b.mid )
 43    assert_equal( 4, a.mid(1) )
 44    assert_equal( 5, b.mid(1) )
 45    assert_equal( 6, b.mid(2) )
 46    assert_equal( 3, b.mid(-1) )
 47  end
 48
 49  def test_middle
 50    a = [1,2,3,4,5]
 51    b = [1,2,3,4,5,6]
 52    assert_equal( 3, a.middle )
 53    assert_equal( [3,4], b.middle )
 54  end
 55
 56  #def test_op_fetch
 57  #  a = ['a','b','c','d','e','f']
 58  #  assert_equal( ['b','f'], a[[1,-1]] )
 59  #end
 60  #
 61  #def test_op_store
 62  #  a = ['a','o','z']
 63  #  a[[0,2]] = ['A','Z']
 64  #  assert_equal( ['A','o','Z'], a )
 65  #  a[[0,-1]] = ['W','Y']
 66  #  assert_equal( ['W','o','Y'], a )
 67  #end
 68
 69  def test_thru
 70    assert_equal( [2,3,4], [0,1,2,3,4,5].thru(2,4) )
 71    assert_equal( [0,1], [0,1,2,3,4,5].thru(0,1) )
 72  end
 73
 74  def test_first_eq
 75    a = [1,2]
 76    a.first = 0
 77    assert_equal( [0,2], a )
 78  end
 79
 80  def test_last_eq
 81    a = [1,2]
 82    a.last = 3
 83    assert_equal( [1,3], a )
 84  end
 85
 86  def test_ends
 87    assert_equal( [1,2,3,4,5].ends, 4 )
 88  end
 89
 90  def test_pos
 91    a = [1,2,3,4,5]
 92    assert_equal( 0, a.pos(1) )
 93    assert_equal( 4, a.pos(-1) )
 94  end
 95
 96  def test_range
 97    a = [1,2,3,4,5]
 98    b = [1,2,3,4,5,6]
 99    assert_equal( (0..4), a.range )
100    assert_equal( (0..5), b.range )
101    assert_equal( (1..3), a.range(2,4) )
102    assert_equal( (1..2), b.range(2,3) )
103    assert_equal( (3..1), b.range(4,2) )
104  end
105
106  def test_first!
107    a = [1,2,3]
108    assert_equal( 1, a.first! )
109    assert_equal( [2,3], a )
110  end
111
112  def test_last!
113    a = [1,2,3]
114    assert_equal( 3, a.last! )
115    assert_equal( [1,2], a )
116  end
117
118end