* numeric.c (ruby_float_step): fix Numeric#step with infinity unit

doesn't works well. [ruby-core:32779]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-10-13 19:17:49 +00:00
Родитель b238a3f3fd
Коммит ded94d1c8c
4 изменённых файлов: 23 добавлений и 5 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Thu Oct 14 04:16:41 2010 NARUSE, Yui <naruse@ruby-lang.org>
* numeric.c (ruby_float_step): fix Numeric#step with infinity unit
doesn't works well. [ruby-core:32779]
Wed Oct 13 23:16:46 2010 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Oct 13 23:16:46 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* tool/enc-unicode.rb: get rid of lots of warnings. * tool/enc-unicode.rb: get rid of lots of warnings.

Просмотреть файл

@ -1621,7 +1621,7 @@ ruby_float_step(VALUE from, VALUE to, VALUE step, int excl)
long i; long i;
if (isinf(unit)) { if (isinf(unit)) {
if (unit > 0) rb_yield(DBL2NUM(beg)); if (unit > 0 ? beg <= end : beg >= end) rb_yield(DBL2NUM(beg));
} }
else { else {
if (err>0.5) err=0.5; if (err>0.5) err=0.5;

Просмотреть файл

@ -27,6 +27,7 @@ class TestNumeric < Test::Unit::TestCase
assert_raise(ArgumentError) { 1 <= a } assert_raise(ArgumentError) { 1 <= a }
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :coerce
def coerce(x); 1.coerce(x); end def coerce(x); 1.coerce(x); end
end end
assert_equal(2, 1 + a) assert_equal(2, 1 + a)
@ -34,6 +35,7 @@ class TestNumeric < Test::Unit::TestCase
assert(1 <= a) assert(1 <= a)
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :coerce
def coerce(x); [x, 1]; end def coerce(x); [x, 1]; end
end end
assert_equal(-1, -a) assert_equal(-1, -a)
@ -95,6 +97,7 @@ class TestNumeric < Test::Unit::TestCase
assert_equal(:ok, a.abs) assert_equal(:ok, a.abs)
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :<
def <(x); false; end def <(x); false; end
end end
@ -150,6 +153,7 @@ class TestNumeric < Test::Unit::TestCase
assert_equal(1, a.truncate) assert_equal(1, a.truncate)
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :to_f
def to_f; 1.4; end def to_f; 1.4; end
end end
@ -160,6 +164,7 @@ class TestNumeric < Test::Unit::TestCase
assert_equal(1, a.truncate) assert_equal(1, a.truncate)
DummyNumeric.class_eval do DummyNumeric.class_eval do
remove_method :to_f
def to_f; -1.5; end def to_f; -1.5; end
end end
@ -202,6 +207,14 @@ class TestNumeric < Test::Unit::TestCase
a = [] a = []
10.step(1, -(2**32)) {|x| a << x } 10.step(1, -(2**32)) {|x| a << x }
assert_equal([10], a) assert_equal([10], a)
a = []
1.step(0, Float::INFINITY) {|x| a << x }
assert_equal([], a)
a = []
0.step(1, -Float::INFINITY) {|x| a << x }
assert_equal([], a)
end end
def test_num2long def test_num2long

Просмотреть файл

@ -175,11 +175,11 @@ class TestString < Test::Unit::TestCase
def o.<=>(x); nil; end def o.<=>(x); nil; end
assert_nil("foo" <=> o) assert_nil("foo" <=> o)
class << o;undef <=>;end class << o;remove_method :<=>;end
def o.<=>(x); 1; end def o.<=>(x); 1; end
assert_equal(-1, "foo" <=> o) assert_equal(-1, "foo" <=> o)
class << o;undef <=>;end class << o;remove_method :<=>;end
def o.<=>(x); 2**100; end def o.<=>(x); 2**100; end
assert_equal(-(2**100), "foo" <=> o) assert_equal(-(2**100), "foo" <=> o)
end end
@ -202,7 +202,7 @@ class TestString < Test::Unit::TestCase
def o.to_str; end def o.to_str; end
def o.==(x); false; end def o.==(x); false; end
assert_equal(false, "foo" == o) assert_equal(false, "foo" == o)
class << o;undef ==;end class << o;remove_method :==;end
def o.==(x); true; end def o.==(x); true; end
assert_equal(true, "foo" == o) assert_equal(true, "foo" == o)
end end
@ -1818,7 +1818,7 @@ class TestString < Test::Unit::TestCase
c.class_eval { attr 1 } c.class_eval { attr 1 }
end end
class << o;undef to_str;end class << o;remove_method :to_str;end
def o.to_str; "foo"; end def o.to_str; "foo"; end
assert_nothing_raised do assert_nothing_raised do
c.class_eval { attr o } c.class_eval { attr o }