summaryrefslogtreecommitdiff
path: root/test/test_prime.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-11 13:14:38 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-03-06 20:54:33 +0900
commite79fc05a4ca672816c6b737d00a85fea4aa6c2b7 (patch)
tree41d17c47d1322b1920ad4706b056d586d0730a80 /test/test_prime.rb
parent2630757fb53f955d45bb67ccf8187d41b581bca1 (diff)
[ruby/prime] Fix Prime.include?
Previously, it would be an infinite loop if passed a non-prime integer. Also, Prime.include? should also provide similar results to Module#include? if passed a Module, so handle that. For consistency with Enumerable#include?, return false if passed other object types. Fixes Ruby Bug 10167. https://github.com/ruby/prime/commit/55dda6aa7f
Diffstat (limited to 'test/test_prime.rb')
-rw-r--r--test/test_prime.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/test_prime.rb b/test/test_prime.rb
index 9db13f08fe..b809d15df7 100644
--- a/test/test_prime.rb
+++ b/test/test_prime.rb
@@ -27,6 +27,14 @@ class TestPrime < Test::Unit::TestCase
assert_equal PRIMES, primes
end
+ def test_include?
+ assert_equal(false, Prime.include?(nil))
+ assert_equal(true, Prime.include?(3))
+ assert_equal(false, Prime.include?(4))
+ assert_equal(true, Prime.include?(Enumerable))
+ assert_equal(false, Prime.include?(Comparable))
+ end
+
def test_integer_each_prime
primes = []
Integer.each_prime(1000) do |p|