summaryrefslogtreecommitdiff
path: root/test/ruby/test_rational.rb
diff options
context:
space:
mode:
authortadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-22 12:27:54 +0000
committertadf <tadf@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-22 12:27:54 +0000
commit8f40b265811a23eef5b8c9e0b677b7d15cd6ea45 (patch)
tree87500a4a23ee3748c74aff1f750eacef665b9cca /test/ruby/test_rational.rb
parent2d302dfd40ee9a4b3183415b19dbc22cf9106ba3 (diff)
* complex.c (nucomp_div): now behaves as quo.
* complex.c (nucomp_s_generic_p): has been removed. * complex.c (nucomp_to_s): adopts new form. * complex.c (nucomp_inspect): ditto. * complex.c (string_to_c_internal): ditto and supports polar form. * complex.c (rb_complex_polar): new. * rational.c (nurat_to_s): did not canonicalize. * rational.c (nurat_inspect): adopts new form. * rational.c (string_to_r_internal): ditto. * include/ruby/intern.h: added a declaration. * lib/complex.rb: added an obsolate class method. * lib/cmath.rb: use scalar? instead of generic?. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18778 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_rational.rb')
-rw-r--r--test/ruby/test_rational.rb47
1 files changed, 31 insertions, 16 deletions
diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb
index 0a72fa12ad..eb52e3e193 100644
--- a/test/ruby/test_rational.rb
+++ b/test/ruby/test_rational.rb
@@ -83,6 +83,8 @@ class Rational_Test < Test::Unit::TestCase
instance_eval{[numerator, denominator]})
assert_equal([0,1], Rational.__send__(:new!, nil).
instance_eval{[numerator, denominator]})
+
+ assert_raise(ZeroDivisionError){Rational.__send__(:new!, 1, 0)}
end
=begin
@@ -621,6 +623,10 @@ class Rational_Test < Test::Unit::TestCase
assert_instance_of(Rational, x)
assert_equal(1, x.numerator)
assert_equal(4, x.denominator)
+
+ unless defined?(Rational::Unify) # maybe bug mathn
+ assert_raise(ZeroDivisionError){0 ** -1}
+ end
end
def test_cmp
@@ -676,8 +682,6 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(true, Rational(2,1) != Rational(1))
assert_equal(false, Rational(1) == nil)
assert_equal(false, Rational(1) == '')
-
- assert_equal(false, Rational(1,2**100) == 1)
end
def test_unify
@@ -698,8 +702,13 @@ class Rational_Test < Test::Unit::TestCase
assert_instance_of(String, c.to_s)
assert_equal('1/2', c.to_s)
- assert_equal('0', Rational(0,2).to_s)
- assert_equal('0', Rational(0,-2).to_s)
+ if defined?(Rational::Unify)
+ assert_equal('0', Rational(0,2).to_s)
+ assert_equal('0', Rational(0,-2).to_s)
+ else
+ assert_equal('0/1', Rational(0,2).to_s)
+ assert_equal('0/1', Rational(0,-2).to_s)
+ end
assert_equal('1/2', Rational(1,2).to_s)
assert_equal('-1/2', Rational(-1,2).to_s)
assert_equal('1/2', Rational(-1,-2).to_s)
@@ -711,7 +720,7 @@ class Rational_Test < Test::Unit::TestCase
c = Rational(1,2)
assert_instance_of(String, c.inspect)
- assert_equal('Rational(1, 2)', c.inspect)
+ assert_equal('(1/2)', c.inspect)
end
def test_marshal
@@ -721,6 +730,10 @@ class Rational_Test < Test::Unit::TestCase
c2 = Marshal.load(s)
assert_equal(c, c2)
assert_instance_of(Rational, c2)
+
+ assert_raise(ZeroDivisionError){
+ Marshal.load("\x04\bU:\rRational[\ai\x06i\x05")
+ }
end
def test_parse
@@ -730,22 +743,22 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(Rational(-5), '-5'.to_r)
assert_equal(Rational(5,3), '5/3'.to_r)
assert_equal(Rational(-5,3), '-5/3'.to_r)
- assert_equal(Rational(5,-3), '5/-3'.to_r)
- assert_equal(Rational(-5,-3), '-5/-3'.to_r)
+# assert_equal(Rational(5,-3), '5/-3'.to_r)
+# assert_equal(Rational(-5,-3), '-5/-3'.to_r)
assert_equal(Rational(5), '5.0'.to_r)
assert_equal(Rational(-5), '-5.0'.to_r)
assert_equal(Rational(5,3), '5.0/3'.to_r)
assert_equal(Rational(-5,3), '-5.0/3'.to_r)
- assert_equal(Rational(5,-3), '5.0/-3'.to_r)
- assert_equal(Rational(-5,-3), '-5.0/-3'.to_r)
+# assert_equal(Rational(5,-3), '5.0/-3'.to_r)
+# assert_equal(Rational(-5,-3), '-5.0/-3'.to_r)
assert_equal(Rational(5), '5e0'.to_r)
assert_equal(Rational(-5), '-5e0'.to_r)
assert_equal(Rational(5,3), '5e0/3'.to_r)
assert_equal(Rational(-5,3), '-5e0/3'.to_r)
- assert_equal(Rational(5,-3), '5e0/-3'.to_r)
- assert_equal(Rational(-5,-3), '-5e0/-3'.to_r)
+# assert_equal(Rational(5,-3), '5e0/-3'.to_r)
+# assert_equal(Rational(-5,-3), '-5e0/-3'.to_r)
assert_equal(Rational(33,100), '0.33'.to_r)
assert_equal(Rational(-33,100), '-0.33'.to_r)
@@ -765,8 +778,8 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(Rational(-5), Rational('-5'))
assert_equal(Rational(5,3), Rational('5/3'))
assert_equal(Rational(-5,3), Rational('-5/3'))
- assert_equal(Rational(5,-3), Rational('5/-3'))
- assert_equal(Rational(-5,-3), Rational('-5/-3'))
+# assert_equal(Rational(5,-3), Rational('5/-3'))
+# assert_equal(Rational(-5,-3), Rational('-5/-3'))
assert_equal(Rational(33,100), Rational('0.33'))
assert_equal(Rational(-33,100), Rational('-0.33'))
@@ -783,8 +796,8 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(Rational(-5.0), Rational('-5.0'))
assert_equal(Rational(5.0,3), Rational('5.0/3'))
assert_equal(Rational(-5.0,3), Rational('-5.0/3'))
- assert_equal(Rational(5.0,-3), Rational('5.0/-3'))
- assert_equal(Rational(-5.0,-3), Rational('-5.0/-3'))
+# assert_equal(Rational(5.0,-3), Rational('5.0/-3'))
+# assert_equal(Rational(-5.0,-3), Rational('-5.0/-3'))
assert_equal(Rational(0), '_'.to_r)
assert_equal(Rational(0), '_5'.to_r)
@@ -933,7 +946,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(Rational(1,2), 1.quo(2))
assert_equal(Rational(5000000000), 10000000000.quo(2))
- assert_equal(Rational(1,2), 1.0.quo(2))
+ assert_equal(0.5, 1.0.quo(2))
assert_equal(Rational(1,4), Rational(1,2).quo(2))
assert_equal(0.5, 1.fdiv(2))
@@ -942,6 +955,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(0.25, Rational(1,2).fdiv(2))
end
+=begin
def test_zero_div
assert_raise(ZeroDivisionError) { Rational(1, 0) }
assert_raise(ZeroDivisionError) { Rational(1, 1) / 0 }
@@ -1043,6 +1057,7 @@ class Rational_Test < Test::Unit::TestCase
assert_equal(1, Rational(2**5000,3).to_f.infinite?)
assert_equal(0, Rational(1, 2**5000).to_f)
end
+=end
def test_fixed_bug
if defined?(Rational::Unify)