1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Move spec/rubyspec to spec/ruby for consistency

* Other ruby implementations use the spec/ruby directory.
  [Misc #13792] [ruby-core:82287]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2017-09-20 20:18:52 +00:00
parent 75bfc6440d
commit 1d15d5f080
4370 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,13 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'prime'
describe "Integer.each_prime" do
it "is transferred to Prime.each" do
Prime.should_receive(:each).with(100).and_yield(2).and_yield(3).and_yield(5)
yielded = []
Integer.each_prime(100) do |prime|
yielded << prime
end
yielded.should == [2,3,5]
end
end

View file

@ -0,0 +1,13 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'prime'
describe "Integer.from_prime_division" do
it "returns the product of the given factorization" do
Integer.from_prime_division([[2,3], [3,3], [5,3], [7,3], [11,3], [13,3], [17,3]]).
should == 2**3 * 3**3 * 5**3 * 7**3 * 11**3 * 13**3 * 17**3
end
it "returns 1 for an empty factorization" do
Integer.from_prime_division([]).should == 1
end
end

View file

@ -0,0 +1,19 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'prime'
describe "Integer#prime_division" do
it "returns an array of a prime factor and a corresponding exponent" do
(2*3*5*7*11*13*17).prime_division.should ==
[[2,1], [3,1], [5,1], [7,1], [11,1], [13,1], [17,1]]
end
it "returns an empty array for 1" do
1.prime_division.should == []
end
it "returns an empty array for -1" do
-1.prime_division.should == [[-1, 1]]
end
it "raises ZeroDivisionError for 0" do
lambda { 0.prime_division }.should raise_error(ZeroDivisionError)
end
end

View file

@ -0,0 +1,17 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require 'prime'
describe "Integer#prime?" do
it "returns a true value for prime numbers" do
2.prime?.should be_true
3.prime?.should be_true
(2**31-1).prime?.should be_true # 8th Mersenne prime (M8)
end
it "returns a false value for composite numbers" do
4.prime?.should be_false
15.prime?.should be_false
(2**32-1).prime?.should be_false
( (2**17-1)*(2**19-1) ).prime?.should be_false # M6*M7
end
end