* test/ruby/test_array.rb: add some tests (for coverage).
* test/ruby/test_bignum.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
34b93543fc
commit
77f3fc3054
@ -1,3 +1,9 @@
|
||||
Tue Jan 19 02:02:32 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* test/ruby/test_array.rb: add some tests (for coverage).
|
||||
|
||||
* test/ruby/test_bignum.rb: ditto.
|
||||
|
||||
Tue Jan 19 01:57:12 2010 Yusuke Endoh <mame@tsg.ne.jp>
|
||||
|
||||
* test/ruby/test_bignum.rb: some coerce definitions (for test) was
|
||||
|
@ -760,6 +760,40 @@ class TestArray < Test::Unit::TestCase
|
||||
assert_match(/reentered/, e.message, '[ruby-dev:34798]')
|
||||
end
|
||||
|
||||
def test_permutation_with_callcc
|
||||
respond_to?(:callcc, true) or require 'continuation'
|
||||
n = 1000
|
||||
cont = nil
|
||||
ary = [1,2,3]
|
||||
begin
|
||||
ary.permutation {
|
||||
callcc {|k| cont = k} unless cont
|
||||
}
|
||||
rescue => e
|
||||
end
|
||||
n -= 1
|
||||
cont.call if 0 < n
|
||||
assert_instance_of(RuntimeError, e)
|
||||
assert_match(/reentered/, e.message)
|
||||
end
|
||||
|
||||
def test_combination_with_callcc
|
||||
respond_to?(:callcc, true) or require 'continuation'
|
||||
n = 1000
|
||||
cont = nil
|
||||
ary = [1,2,3]
|
||||
begin
|
||||
ary.combination(2) {
|
||||
callcc {|k| cont = k} unless cont
|
||||
}
|
||||
rescue => e
|
||||
end
|
||||
n -= 1
|
||||
cont.call if 0 < n
|
||||
assert_instance_of(RuntimeError, e)
|
||||
assert_match(/reentered/, e.message)
|
||||
end
|
||||
|
||||
def test_hash
|
||||
a1 = @cls[ 'cat', 'dog' ]
|
||||
a2 = @cls[ 'cat', 'dog' ]
|
||||
@ -1140,6 +1174,9 @@ class TestArray < Test::Unit::TestCase
|
||||
a = @cls[1, 2, 3, 4, 5]
|
||||
assert_equal(nil, a.slice!(-6,2))
|
||||
assert_equal(@cls[1, 2, 3, 4, 5], a)
|
||||
|
||||
assert_raise(ArgumentError) { @cls[1].slice! }
|
||||
assert_raise(ArgumentError) { @cls[1].slice!(0, 0, 0) }
|
||||
end
|
||||
|
||||
def test_sort
|
||||
@ -1150,6 +1187,8 @@ class TestArray < Test::Unit::TestCase
|
||||
assert_equal(@cls[4, 3, 2, 1], a.sort { |x, y| y <=> x} )
|
||||
assert_equal(@cls[4, 1, 2, 3], a)
|
||||
|
||||
assert_equal(@cls[1, 2, 3, 4], a.sort { |x, y| (x - y) * (2**100) })
|
||||
|
||||
a.fill(1)
|
||||
assert_equal(@cls[1, 1, 1, 1], a.sort)
|
||||
|
||||
@ -1417,6 +1456,7 @@ class TestArray < Test::Unit::TestCase
|
||||
assert_raise(IndexError) { [0][-2] = 1 }
|
||||
assert_raise(IndexError) { [0][LONGP] = 2 }
|
||||
assert_raise(IndexError) { [0][(LONGP + 1) / 2 - 1] = 2 }
|
||||
assert_raise(IndexError) { [0][LONGP..-1] = 2 }
|
||||
a = [0]
|
||||
a[2] = 4
|
||||
assert_equal([0, nil, 4], a)
|
||||
|
@ -175,6 +175,8 @@ class TestBignum < Test::Unit::TestCase
|
||||
def test_to_f
|
||||
assert_nothing_raised { T31P.to_f.to_i }
|
||||
assert_raise(FloatDomainError) { (1024**1024).to_f.to_i }
|
||||
assert_equal(1, (2**50000).to_f.infinite?)
|
||||
assert_equal(-1, (-(2**50000)).to_f.infinite?)
|
||||
end
|
||||
|
||||
def test_cmp
|
||||
@ -414,4 +416,15 @@ class TestBignum < Test::Unit::TestCase
|
||||
assert_in_delta(1.0, @fmax2.fdiv(@fmax2), 0.01)
|
||||
end
|
||||
|
||||
def test_float_fdiv
|
||||
b = 1E+300.to_i
|
||||
assert_equal(b, (b ** 2).fdiv(b))
|
||||
assert(@big.fdiv(0.0 / 0.0).nan?)
|
||||
end
|
||||
|
||||
def test_obj_fdiv
|
||||
o = Object.new
|
||||
def o.coerce(x); [x, 2**100]; end
|
||||
assert_equal((2**200).to_f, (2**300).fdiv(o))
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user