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

Language Ruby Lines 119
MD5 Hash e4afc3a2c0600d2a447067a4448fa688 Estimated Cost $1,830 (why?)
Repository https://bitbucket.org/mediashelf/fedora-migrator View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
require 'facets/array/indexable.rb'
require 'test/unit'

class TestArray < Test::Unit::TestCase

  #def test_op_mod
  #  a = [:A,:B,:C]
  #  assert_equal( a[1], a/1 )
  #  assert_equal( :B, a/1 )
  #end
  #
  #def test_op_div
  #  a = [:A,:B,:C]
  #  assert_equal( a[1], a/1 )
  #  assert_equal( :B, a/1 )
  #end

  def test_head
    a = [1,2,3,4,5]
    assert_equal( [1], a.head )
  end

  def test_tail
    a = [1,2,3,4,5]
    assert_equal( [2,3,4,5], a.tail )
  end

  def test_foot
    a = [1,2,3,4,5]
    assert_equal( [5], a.foot )
  end

  def test_body
    a = [1,2,3,4,5]
    assert_equal( [1,2,3,4], a.body )
  end

  def test_mid
    a = [1,2,3,4,5]
    b = [1,2,3,4,5,6]
    assert_equal( 3, a.mid )
    assert_equal( 4, b.mid )
    assert_equal( 4, a.mid(1) )
    assert_equal( 5, b.mid(1) )
    assert_equal( 6, b.mid(2) )
    assert_equal( 3, b.mid(-1) )
  end

  def test_middle
    a = [1,2,3,4,5]
    b = [1,2,3,4,5,6]
    assert_equal( 3, a.middle )
    assert_equal( [3,4], b.middle )
  end

  #def test_op_fetch
  #  a = ['a','b','c','d','e','f']
  #  assert_equal( ['b','f'], a[[1,-1]] )
  #end
  #
  #def test_op_store
  #  a = ['a','o','z']
  #  a[[0,2]] = ['A','Z']
  #  assert_equal( ['A','o','Z'], a )
  #  a[[0,-1]] = ['W','Y']
  #  assert_equal( ['W','o','Y'], a )
  #end

  def test_thru
    assert_equal( [2,3,4], [0,1,2,3,4,5].thru(2,4) )
    assert_equal( [0,1], [0,1,2,3,4,5].thru(0,1) )
  end

  def test_first_eq
    a = [1,2]
    a.first = 0
    assert_equal( [0,2], a )
  end

  def test_last_eq
    a = [1,2]
    a.last = 3
    assert_equal( [1,3], a )
  end

  def test_ends
    assert_equal( [1,2,3,4,5].ends, 4 )
  end

  def test_pos
    a = [1,2,3,4,5]
    assert_equal( 0, a.pos(1) )
    assert_equal( 4, a.pos(-1) )
  end

  def test_range
    a = [1,2,3,4,5]
    b = [1,2,3,4,5,6]
    assert_equal( (0..4), a.range )
    assert_equal( (0..5), b.range )
    assert_equal( (1..3), a.range(2,4) )
    assert_equal( (1..2), b.range(2,3) )
    assert_equal( (3..1), b.range(4,2) )
  end

  def test_first!
    a = [1,2,3]
    assert_equal( 1, a.first! )
    assert_equal( [2,3], a )
  end

  def test_last!
    a = [1,2,3]
    assert_equal( 3, a.last! )
    assert_equal( [1,2], a )
  end

end
Back to Top