Debian Codegraph @

test/-ext-/float/test_nextafter.rb

raw
1 # frozen_string_literal: false
2 require 'test/unit'
3 require "-test-/float"
4
5 class TestFloatExt < Test::Unit::TestCase
6 NEXTAFTER_VALUES = [
7 -Float::INFINITY,
8 -Float::MAX,
9 -100.0,
10 -1.0-Float::EPSILON,
11 -1.0,
12 -Float::EPSILON,
13 -Float::MIN/2,
14 -Math.ldexp(0.5, Float::MIN_EXP - Float::MANT_DIG + 1),
15 -0.0,
16 0.0,
17 Math.ldexp(0.5, Float::MIN_EXP - Float::MANT_DIG + 1),
18 Float::MIN/2,
19 Float::MIN,
20 Float::EPSILON,
21 1.0,
22 1.0+Float::EPSILON,
23 100.0,
24 Float::MAX,
25 Float::INFINITY,
26 Float::NAN
27 ]
28
29 test_number = 0
30 NEXTAFTER_VALUES.each {|n1|
31 NEXTAFTER_VALUES.each {|n2|
32 tag = n2.infinite? ? "ruby" : "other"
33 test_name = "test_nextafter_#{test_number}_#{tag}_#{n1}_#{n2}"
34 test_number += 1
35 define_method(test_name) {
36 v1 = Bug::Float.missing_nextafter(n1, n2)
37 v2 = Bug::Float.system_nextafter(n1, n2)
38 assert_kind_of(Float, v1)
39 assert_kind_of(Float, v2)
40 if v1.nan?
41 assert(v2.nan?, "Bug::Float.system_nextafter(#{n1}, #{n2}).nan?")
42 else
43 assert_equal(v1, v2,
44 "Bug::Float.missing_nextafter(#{'%a' % n1}, #{'%a' % n2}) = #{'%a' % v1} != " +
45 "#{'%a' % v2} = Bug::Float.system_nextafter(#{'%a' % n1}, #{'%a' % n2})")
46 if v1 == 0
47 s1 = 1.0/v1 < 0 ? "negative-zero" : "positive-zero"
48 s2 = 1.0/v2 < 0 ? "negative-zero" : "positive-zero"
49 begin
50 assert_equal(s1, s2,
51 "Bug::Float.missing_nextafter(#{'%a' % n1}, #{'%a' % n2}) = #{'%a' % v1} != " +
52 "#{'%a' % v2} = Bug::Float.system_nextafter(#{'%a' % n1}, #{'%a' % n2})")
53 rescue Test::Unit::AssertionFailedError
54 if /aix/ =~ RUBY_PLATFORM
55 omit "Known bug in nextafter(3) on AIX"
56 end
57 raise $!
58 end
59 end
60 end
61 }
62 }
63 }
64
65 end