diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-09-20 20:18:52 +0000 |
commit | 1d15d5f08032acf1b7bceacbb450d617ff6e0931 (patch) | |
tree | a3785a79899302bc149e4a6e72f624ac27dc1f10 /spec/ruby/core/float/prev_float_spec.rb | |
parent | 75bfc6440d595bf339007f4fb280fd4d743e89c1 (diff) |
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
Diffstat (limited to 'spec/ruby/core/float/prev_float_spec.rb')
-rw-r--r-- | spec/ruby/core/float/prev_float_spec.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/spec/ruby/core/float/prev_float_spec.rb b/spec/ruby/core/float/prev_float_spec.rb new file mode 100644 index 0000000000..e07d78c44c --- /dev/null +++ b/spec/ruby/core/float/prev_float_spec.rb @@ -0,0 +1,49 @@ +require File.expand_path('../../../spec_helper', __FILE__) + +describe "Float#prev_float" do + it "returns a float the smallest possible step smaller than the receiver" do + barely_negative = 0.0.prev_float + barely_negative.should == 0.0.prev_float + + barely_negative.should < 0.0 + barely_negative.should > barely_negative.prev_float + + midpoint = barely_negative / 2 + [0.0, barely_negative].should include midpoint + end + + it "returns -Float::INFINITY for -Float::INFINITY" do + (-Float::INFINITY).prev_float.should == -Float::INFINITY + end + + it "steps directly between MAX and INFINITY" do + Float::INFINITY.prev_float.should == Float::MAX + (-Float::MAX).prev_float.should == -Float::INFINITY + end + + it "steps directly between 1.0 and 1.0 - EPSILON/2" do + 1.0.prev_float.should == 1.0 - Float::EPSILON/2 + end + + it "steps directly between -1.0 and -1.0 - EPSILON" do + (-1.0).prev_float.should == -1.0 - Float::EPSILON + end + + it "reverses the effect of next_float for all Floats except -INFINITY and -0.0" do + num = rand + num.next_float.prev_float.should == num + end + + it "returns positive zero when stepping downward from just above zero" do + x = 0.0.next_float.prev_float + (1/x).should == Float::INFINITY + end + + it "gives the same result for -0.0 as for +0.0" do + (0.0).prev_float.should == (-0.0).prev_float + end + + it "returns NAN if NAN was the receiver" do + Float::NAN.prev_float.nan?.should == true + end +end |