From a821725ab0df0cbec2a8644498644c9f826d49c8 Mon Sep 17 00:00:00 2001 From: tadf Date: Thu, 4 Dec 2008 13:14:25 +0000 Subject: * test/ruby/test_complex.rb: added some tests. * test/ruby/test_rational.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20514 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_complex.rb | 29 ++++++++++++++++++++++++++++- test/ruby/test_rational.rb | 14 ++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'test/ruby') diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index 5d4916e1d0..d5a8a18524 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -27,7 +27,7 @@ class Complex_Test < Test::Unit::TestCase c2 = c - 1 assert_instance_of(ComplexSub, c2) - c3 = c - c + c3 = c - c2 assert_instance_of(ComplexSub, c3) s = Marshal.dump(c) @@ -71,6 +71,12 @@ class Complex_Test < Test::Unit::TestCase h[Complex(0.0,0.0)] = 9.0 assert_equal(5, h.size) + + if (0.0/0).nan? && !((0.0/0).eql?(0.0/0)) + h = {} + 3.times{h[Complex(0.0/0)] = 1} + assert_equal(3, h.size) + end end def test_freeze @@ -124,6 +130,13 @@ class Complex_Test < Test::Unit::TestCase assert_raise(ArgumentError){Complex(Object.new)} assert_raise(ArgumentError){Complex()} assert_raise(ArgumentError){Complex(1,2,3)} + + if (0.0/0).nan? + assert_nothing_raised{Complex(0.0/0)} + end + if (1.0/0).infinite? + assert_nothing_raised{Complex(1.0/0)} + end end def test_attr @@ -483,6 +496,13 @@ class Complex_Test < Test::Unit::TestCase assert_equal(true, Complex(2,1) != Complex(1)) assert_equal(false, Complex(1) == nil) assert_equal(false, Complex(1) == '') + + nan = 0.0 / 0 + if nan.nan? && nan != nan + assert_equal(false, Complex(nan, 0) == Complex(nan, 0)) + assert_equal(false, Complex(0, nan) == Complex(0, nan)) + assert_equal(false, Complex(nan, nan) == Complex(nan, nan)) + end end def test_unify @@ -822,6 +842,13 @@ class Complex_Test < Test::Unit::TestCase c = Complex(1,2).to_c assert_equal([1, 2], [c.real, c.imag]) + + if (0.0/0).nan? + assert_nothing_raised{(0.0/0).to_c} + end + if (1.0/0).infinite? + assert_nothing_raised{(1.0/0).to_c} + end end def test_supp diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 5758749d5e..703d56a2ab 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -129,6 +129,13 @@ class Rational_Test < Test::Unit::TestCase assert_raise(ArgumentError){Rational(Object.new)} assert_raise(ArgumentError){Rational()} assert_raise(ArgumentError){Rational(1,2,3)} + + if (0.0/0).nan? + assert_raise(FloatDomainError){Rational(0.0/0)} + end + if (1.0/0).infinite? + assert_raise(FloatDomainError){Rational(1.0/0)} + end end def test_attr @@ -935,6 +942,13 @@ class Rational_Test < Test::Unit::TestCase assert_raise(RangeError){Complex(1,2).to_r} end end + + if (0.0/0).nan? + assert_raise(FloatDomainError){(0.0/0).to_r} + end + if (1.0/0).infinite? + assert_raise(FloatDomainError){(1.0/0).to_r} + end end def test_gcdlcm -- cgit v1.2.3