summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_enumerator.rb9
-rw-r--r--test/ruby/test_lazy_enumerator.rb9
2 files changed, 16 insertions, 2 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb
index 86cab539ab..1889f58b69 100644
--- a/test/ruby/test_enumerator.rb
+++ b/test/ruby/test_enumerator.rb
@@ -657,8 +657,13 @@ class TestEnumerator < Test::Unit::TestCase
end
def test_uniq
- assert_equal([1, 2, 3, 4, 5, 10],
- (1..Float::INFINITY).lazy.uniq{|x| (x**2) % 10 }.first(6))
+ u = [0, 1, 0, 1].to_enum.lazy.uniq
+ assert_equal([0, 1], u.force)
+ assert_equal([0, 1], u.force)
+
+ u = (1..Float::INFINITY).lazy.uniq{|x| (x**2) % 10 }
+ assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
+ assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
end
end
diff --git a/test/ruby/test_lazy_enumerator.rb b/test/ruby/test_lazy_enumerator.rb
index 22028283ce..03371c912a 100644
--- a/test/ruby/test_lazy_enumerator.rb
+++ b/test/ruby/test_lazy_enumerator.rb
@@ -569,4 +569,13 @@ EOS
[1, 2, 3].lazy.map(&:undefined).map(&:to_s).force
end
end
+
+ def test_uniq
+ u = (1..Float::INFINITY).lazy.uniq do |x|
+ raise "too big" if x > 10000
+ (x**2) % 10
+ end
+ assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
+ assert_equal([1, 2, 3, 4, 5, 10], u.first(6))
+ end
end