diff options
author | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-18 17:03:16 +0000 |
---|---|---|
committer | mame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-01-18 17:03:16 +0000 |
commit | 77f3fc305491dab95b02d9d60c5f883f9e5b05df (patch) | |
tree | 49f0968711489a5de54aec13d6d5dc4c09d6ea87 | |
parent | 34b93543fcac01b1342a9eb084a4ef16f86b5a16 (diff) |
* 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
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | test/ruby/test_array.rb | 40 | ||||
-rw-r--r-- | test/ruby/test_bignum.rb | 13 |
3 files changed, 59 insertions, 0 deletions
@@ -1,3 +1,9 @@ +Tue Jan 19 02:02:32 2010 Yusuke Endoh <[email protected]> + + * 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 <[email protected]> * test/ruby/test_bignum.rb: some coerce definitions (for test) was diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 0797190447..7bfd9dde87 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -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) diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb index 8c496a36e6..cba935f121 100644 --- a/test/ruby/test_bignum.rb +++ b/test/ruby/test_bignum.rb @@ -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 |