diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-14 03:46:37 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-05-14 03:46:37 +0000 |
| commit | e86c6b7212356a20b8b719a98329860a69cc3b12 (patch) | |
| tree | f29281bb0c0e6e941876fdc629adf1d31e1283c8 /test | |
| parent | 61bb5f0d663c1bb48f048748dcce20dadc00c125 (diff) | |
| download | ruby-e86c6b7212356a20b8b719a98329860a69cc3b12.tar.gz ruby-e86c6b7212356a20b8b719a98329860a69cc3b12.tar.xz ruby-e86c6b7212356a20b8b719a98329860a69cc3b12.zip | |
* array.c (rb_ary_count): Override Enumerable#count for better
performance.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16412 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
| -rw-r--r-- | test/ruby/test_array.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 3775c1f54..a5b473560 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -537,6 +537,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')) |
