diff options
| author | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 12:43:45 +0000 |
|---|---|---|
| committer | knu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-06-03 12:43:45 +0000 |
| commit | e921f413f7a8fc8704abc93c0cd1e179fd9f165d (patch) | |
| tree | 36dfafe1b40e9a31f11f2f4522a3821b210c79aa /test/ruby | |
| parent | 416fa0e817260458fa7a1cf0a195ac5bb970cbbb (diff) | |
| download | ruby-e921f413f7a8fc8704abc93c0cd1e179fd9f165d.tar.gz ruby-e921f413f7a8fc8704abc93c0cd1e179fd9f165d.tar.xz ruby-e921f413f7a8fc8704abc93c0cd1e179fd9f165d.zip | |
* enumerator.c (enumerator_with_memo): New method: with_memo().
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@16795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_enumerator.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 31382b03b..8645b7acf 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -91,6 +91,25 @@ class TestEnumerator < Test::Unit::TestCase assert_equal([[1,0],[2,1],[3,2]], @obj.to_enum(:foo, 1, 2, 3).with_index.to_a) end + def test_with_memo + r = 1..10 + assert_equal([55, 3628800], (1..10).each.with_memo([0,1]) {|i, memo| + memo[0] += i + memo[1] *= i + }) + + a = [2,5,2,1,5,3,4,2,1,0] + a.delete_if.with_memo({}) {|i, seen| + if seen.key?(i) + true + else + seen[i] = true + false + end + } + assert_equal([2, 5, 1, 3, 4, 0], a) + end + def test_next_rewind e = @obj.to_enum(:foo, 1, 2, 3) assert_equal(1, e.next) |
