1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/rubyspec/library/bigdecimal/nonzero_spec.rb
eregon 95e8c48dd3 Add in-tree mspec and ruby/spec
* For easier modifications of ruby/spec by MRI developers.
* .gitignore: track changes under spec.
* spec/mspec, spec/rubyspec: add in-tree mspec and ruby/spec.
  These files can therefore be updated like any other file in MRI.
  Instructions are provided in spec/README.
  [Feature #13156] [ruby-core:79246]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-07 12:04:49 +00:00

29 lines
1,001 B
Ruby

require File.expand_path('../../../spec_helper', __FILE__)
require 'bigdecimal'
describe "BigDecimal#nonzero?" do
it "returns self if self doesn't equal zero" do
# documentation says, it returns true. (04/10/08)
e2_plus = BigDecimal("2E40001")
e3_minus = BigDecimal("3E-20001")
infinity = BigDecimal("Infinity")
infinity_minus = BigDecimal("-Infinity")
nan = BigDecimal("NaN")
infinity.nonzero?.should equal(infinity)
infinity_minus.nonzero?.should equal(infinity_minus)
nan.nonzero?.should equal(nan)
e3_minus.nonzero?.should equal(e3_minus)
e2_plus.nonzero?.should equal(e2_plus)
end
it "returns nil otherwise" do
# documentation states, it should return false. (04/10/08)
really_small_zero = BigDecimal("0E-200000000")
really_big_zero = BigDecimal("0E200000000000")
really_small_zero.nonzero?.should == nil
really_big_zero.nonzero?.should == nil
BigDecimal("0.000000000000000000000000").nonzero?.should == nil
end
end