summaryrefslogtreecommitdiff
path: root/test/ruby/test_float.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_float.rb')
-rw-r--r--test/ruby/test_float.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/ruby/test_float.rb b/test/ruby/test_float.rb
index 3ee0a23a63..ed8f2992ed 100644
--- a/test/ruby/test_float.rb
+++ b/test/ruby/test_float.rb
@@ -619,4 +619,39 @@ class TestFloat < Test::Unit::TestCase
assert_in_epsilon(10.0, ("1."+"1"*300000).to_f*9)
end;
end
+
+ def test_next_float
+ smallest = 0.0.next_float
+ assert_equal(-Float::MAX, (-Float::INFINITY).next_float)
+ assert_operator(-Float::MAX, :<, (-Float::MAX).next_float)
+ assert_equal(Float::EPSILON/2, (-1.0).next_float + 1.0)
+ assert_operator(0.0, :<, smallest)
+ assert_operator([0.0, smallest], :include?, smallest/2)
+ assert_equal(Float::EPSILON, 1.0.next_float - 1.0)
+ assert_equal(Float::INFINITY, Float::MAX.next_float)
+ assert_equal(Float::INFINITY, Float::INFINITY.next_float)
+ assert(Float::NAN.next_float.nan?)
+ end
+
+ def test_prev_float
+ smallest = 0.0.next_float
+ assert_equal(-Float::INFINITY, (-Float::INFINITY).prev_float)
+ assert_equal(-Float::INFINITY, (-Float::MAX).prev_float)
+ assert_equal(-Float::EPSILON, (-1.0).prev_float + 1.0)
+ assert_equal(-smallest, 0.0.prev_float)
+ assert_operator([0.0, 0.0.prev_float], :include?, 0.0.prev_float/2)
+ assert_equal(-Float::EPSILON/2, 1.0.prev_float - 1.0)
+ assert_operator(Float::MAX, :>, Float::MAX.prev_float)
+ assert_equal(Float::MAX, Float::INFINITY.prev_float)
+ assert(Float::NAN.prev_float.nan?)
+ end
+
+ def test_next_prev_float_zero
+ z = 0.0.next_float.prev_float
+ assert_equal(0.0, z)
+ assert_equal(Float::INFINITY, 1.0/z)
+ z = 0.0.prev_float.next_float
+ assert_equal(0.0, z)
+ assert_equal(-Float::INFINITY, 1.0/z)
+ end
end