summaryrefslogtreecommitdiff
path: root/spec/ruby/core/rational/to_f_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/rational/to_f_spec.rb')
-rw-r--r--spec/ruby/core/rational/to_f_spec.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/spec/ruby/core/rational/to_f_spec.rb b/spec/ruby/core/rational/to_f_spec.rb
index 92ff2444b4..40e3f11c0c 100644
--- a/spec/ruby/core/rational/to_f_spec.rb
+++ b/spec/ruby/core/rational/to_f_spec.rb
@@ -1,5 +1,16 @@
-require File.expand_path('../../../shared/rational/to_f', __FILE__)
+require_relative "../../spec_helper"
describe "Rational#to_f" do
- it_behaves_like(:rational_to_f, :to_f)
+ it "returns self converted to a Float" do
+ Rational(3, 4).to_f.should.eql?(0.75)
+ Rational(3, -4).to_f.should.eql?(-0.75)
+ Rational(-1, 4).to_f.should.eql?(-0.25)
+ Rational(-1, -4).to_f.should.eql?(0.25)
+ end
+
+ it "converts to a Float for large numerator and denominator" do
+ num = 1000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146010000000000000000000000000000000000048148248609680896326399448564623182963452541226153892315137780403285956264146009
+ den = 2000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
+ Rational(num, den).to_f.should == 500.0
+ end
end