PageRenderTime 25ms CodeModel.GetById 0ms RepoModel.GetById 0ms 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
Possible License(s): GPL-3.0, GPL-2.0, IPL-1.0, AGPL-1.0, LGPL-3.0
  1. require 'facets/array/indexable.rb'
  2. require 'test/unit'
  3. class TestArray < Test::Unit::TestCase
  4. #def test_op_mod
  5. # a = [:A,:B,:C]
  6. # assert_equal( a[1], a/1 )
  7. # assert_equal( :B, a/1 )
  8. #end
  9. #
  10. #def test_op_div
  11. # a = [:A,:B,:C]
  12. # assert_equal( a[1], a/1 )
  13. # assert_equal( :B, a/1 )
  14. #end
  15. def test_head
  16. a = [1,2,3,4,5]
  17. assert_equal( [1], a.head )
  18. end
  19. def test_tail
  20. a = [1,2,3,4,5]
  21. assert_equal( [2,3,4,5], a.tail )
  22. end
  23. def test_foot
  24. a = [1,2,3,4,5]
  25. assert_equal( [5], a.foot )
  26. end
  27. def test_body
  28. a = [1,2,3,4,5]
  29. assert_equal( [1,2,3,4], a.body )
  30. end
  31. def test_mid
  32. a = [1,2,3,4,5]
  33. b = [1,2,3,4,5,6]
  34. assert_equal( 3, a.mid )
  35. assert_equal( 4, b.mid )
  36. assert_equal( 4, a.mid(1) )
  37. assert_equal( 5, b.mid(1) )
  38. assert_equal( 6, b.mid(2) )
  39. assert_equal( 3, b.mid(-1) )
  40. end
  41. def test_middle
  42. a = [1,2,3,4,5]
  43. b = [1,2,3,4,5,6]
  44. assert_equal( 3, a.middle )
  45. assert_equal( [3,4], b.middle )
  46. end
  47. #def test_op_fetch
  48. # a = ['a','b','c','d','e','f']
  49. # assert_equal( ['b','f'], a[[1,-1]] )
  50. #end
  51. #
  52. #def test_op_store
  53. # a = ['a','o','z']
  54. # a[[0,2]] = ['A','Z']
  55. # assert_equal( ['A','o','Z'], a )
  56. # a[[0,-1]] = ['W','Y']
  57. # assert_equal( ['W','o','Y'], a )
  58. #end
  59. def test_thru
  60. assert_equal( [2,3,4], [0,1,2,3,4,5].thru(2,4) )
  61. assert_equal( [0,1], [0,1,2,3,4,5].thru(0,1) )
  62. end
  63. def test_first_eq
  64. a = [1,2]
  65. a.first = 0
  66. assert_equal( [0,2], a )
  67. end
  68. def test_last_eq
  69. a = [1,2]
  70. a.last = 3
  71. assert_equal( [1,3], a )
  72. end
  73. def test_ends
  74. assert_equal( [1,2,3,4,5].ends, 4 )
  75. end
  76. def test_pos
  77. a = [1,2,3,4,5]
  78. assert_equal( 0, a.pos(1) )
  79. assert_equal( 4, a.pos(-1) )
  80. end
  81. def test_range
  82. a = [1,2,3,4,5]
  83. b = [1,2,3,4,5,6]
  84. assert_equal( (0..4), a.range )
  85. assert_equal( (0..5), b.range )
  86. assert_equal( (1..3), a.range(2,4) )
  87. assert_equal( (1..2), b.range(2,3) )
  88. assert_equal( (3..1), b.range(4,2) )
  89. end
  90. def test_first!
  91. a = [1,2,3]
  92. assert_equal( 1, a.first! )
  93. assert_equal( [2,3], a )
  94. end
  95. def test_last!
  96. a = [1,2,3]
  97. assert_equal( 3, a.last! )
  98. assert_equal( [1,2], a )
  99. end
  100. end