mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
merge revision(s) 23730:
* numeric.c (flo_cmp): Infinity is greater than any bignum number. [ruby-dev:38672] * bignum.c (rb_big_cmp): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23730 b2dd03c8-39d4-4d8f-98ff-823fe69b080e Signed-off-by: URABE, Shyouhei <shyouhei@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@34000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
95a7aabe1e
commit
700acefade
4 changed files with 47 additions and 1 deletions
|
@ -144,4 +144,31 @@ class TestFloat < Test::Unit::TestCase
|
|||
assert_operator((-4611686018427387905.0).to_i, :<, 0)
|
||||
assert_operator((-4611686018427387906.0).to_i, :<, 0)
|
||||
end
|
||||
|
||||
def test_cmp
|
||||
inf = 1.0 / 0.0
|
||||
nan = inf / inf
|
||||
assert_equal(0, 1.0 <=> 1.0)
|
||||
assert_equal(1, 1.0 <=> 0.0)
|
||||
assert_equal(-1, 1.0 <=> 2.0)
|
||||
assert_nil(1.0 <=> nil)
|
||||
assert_nil(1.0 <=> nan)
|
||||
assert_nil(nan <=> 1.0)
|
||||
|
||||
assert_equal(0, 1.0 <=> 1)
|
||||
assert_equal(1, 1.0 <=> 0)
|
||||
assert_equal(-1, 1.0 <=> 2)
|
||||
|
||||
assert_equal(-1, 1.0 <=> 2**32)
|
||||
|
||||
assert_equal(1, inf <=> (Float::MAX.to_i*2))
|
||||
assert_equal(-1, -inf <=> (-Float::MAX.to_i*2))
|
||||
assert_equal(-1, (Float::MAX.to_i*2) <=> inf)
|
||||
assert_equal(1, (-Float::MAX.to_i*2) <=> -inf)
|
||||
|
||||
assert_raise(ArgumentError) { 1.0 > nil }
|
||||
assert_raise(ArgumentError) { 1.0 >= nil }
|
||||
assert_raise(ArgumentError) { 1.0 < nil }
|
||||
assert_raise(ArgumentError) { 1.0 <= nil }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue