mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_count): Override Enumerable#count for better
performance. (rb_ary_nitems): Undo the backport. Use #count {} instead. * enumerator.c (enumerator_iter_i): Remove an unused function. (enumerator_with_index, enumerator_each): Remove unused variables. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@16417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e9d69ca0ce
commit
d007e7d20f
5 changed files with 62 additions and 33 deletions
|
@ -528,6 +528,14 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([1, 2, 3, 1, 2, 3], a)
|
||||
end
|
||||
|
||||
def test_count
|
||||
a = @cls[1, 2, 3, 1, 2]
|
||||
assert_equal(2, a.count(1))
|
||||
assert_equal(3, a.count {|x| x % 2 == 1 })
|
||||
assert_equal(2, a.count(1) {|x| x % 2 == 1 })
|
||||
assert_raise(ArgumentError) { a.count(0, 1) }
|
||||
end
|
||||
|
||||
def test_delete
|
||||
a = @cls[*('cab'..'cat').to_a]
|
||||
assert_equal('cap', a.delete('cap'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue