Commit dcd5d0ff authored by YAMAMOTO Masaya's avatar YAMAMOTO Masaya

Test for MRB_WITHOUT_FLOAT

parent acdc2d1f
No related merge requests found
......@@ -94,10 +94,12 @@ mrb_init_test_driver(mrb_state *mrb, mrb_bool verbose)
mrb_define_const(mrb, mrbtest, "FIXNUM_MIN", mrb_fixnum_value(MRB_INT_MIN));
mrb_define_const(mrb, mrbtest, "FIXNUM_BIT", mrb_fixnum_value(MRB_INT_BIT));
#ifndef MRB_WITHOUT_FLOAT
#ifdef MRB_USE_FLOAT
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-6));
#else
mrb_define_const(mrb, mrbtest, "FLOAT_TOLERANCE", mrb_float_value(mrb, 1e-12));
#endif
#endif
if (verbose) {
......
......@@ -7,6 +7,10 @@ MRuby::Gem::Specification.new('mruby-test') do |spec|
spec.add_dependency('mruby-compiler', :core => 'mruby-compiler')
spec.test_rbfiles = Dir.glob("#{MRUBY_ROOT}/test/t/*.rb")
if build.cc.defines.flatten.include?("MRB_WITHOUT_FLOAT")
spec.test_rbfiles.delete("#{MRUBY_ROOT}/test/t/float.rb")
end
clib = "#{build_dir}/mrbtest.c"
mlib = clib.ext(exts.object)
......
......@@ -55,7 +55,7 @@ assert('Array#[]', '15.2.12.5.4') do
assert_equal(nil, [1,2,3].[](-4))
a = [ "a", "b", "c", "d", "e" ]
assert_equal("b", a[1.1])
assert_equal("b", a[1.1]) if class_defined?("Float")
assert_equal(["b", "c"], a[1,2])
assert_equal(["b", "c", "d"], a[1..-2])
end
......
......@@ -358,7 +358,7 @@ assert('singleton tests') do
7
end
end
end
end if class_defined?("Float")
end
assert('clone Class') do
......
......@@ -8,7 +8,7 @@ end
assert('Hash#==', '15.2.13.4.1') do
assert_true({ 'abc' => 'abc' } == { 'abc' => 'abc' })
assert_false({ 'abc' => 'abc' } == { 'cba' => 'cba' })
assert_true({ :equal => 1 } == { :equal => 1.0 })
assert_true({ :equal => 1 } == { :equal => 1.0 }) if class_defined?("Float")
assert_false({ :a => 1 } == true)
end
......
......@@ -7,56 +7,65 @@ end
assert('Integer#+', '15.2.8.3.1') do
a = 1+1
b = 1+1.0
b = 1+1.0 if class_defined?("Float")
assert_equal 2, a
assert_equal 2.0, b
assert_equal 2.0, b if class_defined?("Float")
assert_raise(TypeError){ 0+nil }
assert_raise(TypeError){ 1+nil }
c = Mrbtest::FIXNUM_MAX + 1
d = Mrbtest::FIXNUM_MAX.__send__(:+, 1)
e = Mrbtest::FIXNUM_MAX + 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
if class_defined?("Float")
e = Mrbtest::FIXNUM_MAX + 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
end
assert('Integer#-', '15.2.8.3.2') do
a = 2-1
b = 2-1.0
b = 2-1.0 if class_defined?("Float")
assert_equal 1, a
assert_equal 1.0, b
assert_equal 1.0, b if class_defined?("Float")
c = Mrbtest::FIXNUM_MIN - 1
d = Mrbtest::FIXNUM_MIN.__send__(:-, 1)
e = Mrbtest::FIXNUM_MIN - 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
if class_defined?("Float")
e = Mrbtest::FIXNUM_MIN - 1.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
end
assert('Integer#*', '15.2.8.3.3') do
a = 1*1
b = 1*1.0
b = 1*1.0 if class_defined?("Float")
assert_equal 1, a
assert_equal 1.0, b
assert_equal 1.0, b if class_defined?("Float")
assert_raise(TypeError){ 0*nil }
assert_raise(TypeError){ 1*nil }
c = Mrbtest::FIXNUM_MAX * 2
d = Mrbtest::FIXNUM_MAX.__send__(:*, 2)
e = Mrbtest::FIXNUM_MAX * 2.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
if class_defined?("Float")
e = Mrbtest::FIXNUM_MAX * 2.0
assert_equal Float, c.class
assert_equal Float, d.class
assert_float e, c
assert_float e, d
end
end
assert('Integer#/', '15.2.8.3.4') do
......@@ -218,7 +227,7 @@ end
assert('Integer#to_f', '15.2.8.3.23') do
assert_equal 1.0, 1.to_f
end
end if class_defined?("Float")
assert('Integer#to_i', '15.2.8.3.24') do
assert_equal 1, 1.to_i
......
......@@ -15,7 +15,7 @@ end
assert('Numeric#abs', '15.2.7.4.3') do
assert_equal(1, 1.abs)
assert_equal(1.0, -1.abs)
assert_equal(1.0, -1.abs) if class_defined?("Float")
end
assert('Numeric#pow') do
......
......@@ -8,7 +8,7 @@ end
assert('Range#==', '15.2.14.4.1') do
assert_true (1..10) == (1..10)
assert_false (1..10) == (1..100)
assert_true (1..10) == Range.new(1.0, 10.0)
assert_true (1..10) == Range.new(1.0, 10.0) if class_defined?("Float")
end
assert('Range#===', '15.2.14.4.2') do
......
......@@ -154,10 +154,11 @@ assert('String#[]=') do
d[-10] = 'X'
end
e = 'abc'
e[1.1] = 'X'
assert_equal 'aXc', e
if class_defined?("Float")
e = 'abc'
e[1.1] = 'X'
assert_equal 'aXc', e
end
# length of args is 2
a1 = 'abc'
......@@ -629,7 +630,7 @@ assert('String#to_f', '15.2.10.5.38') do
assert_float(12345.6789, c)
assert_float(0, d)
assert_float(Float::INFINITY, e)
end
end if class_defined?("Float")
assert('String#to_i', '15.2.10.5.39') do
a = ''.to_i
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment