diff options
Diffstat (limited to 'test/ruby/test_complexrational.rb')
| -rw-r--r-- | test/ruby/test_complexrational.rb | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/test/ruby/test_complexrational.rb b/test/ruby/test_complexrational.rb index cef4074afa..31d11fe317 100644 --- a/test/ruby/test_complexrational.rb +++ b/test/ruby/test_complexrational.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: false require 'test/unit' class ComplexRational_Test < Test::Unit::TestCase def test_rat_srat - skip unless defined?(Rational) + omit unless defined?(Rational) c = SimpleRat(1,3) cc = Rational(3,2) @@ -88,7 +89,7 @@ class ComplexRational_Test < Test::Unit::TestCase end def test_comp_srat - skip unless defined?(Rational) + omit unless defined?(Rational) c = Complex(SimpleRat(2,3),SimpleRat(1,2)) cc = Complex(Rational(3,2),Rational(2,1)) @@ -101,7 +102,7 @@ class ComplexRational_Test < Test::Unit::TestCase assert_equal(Complex(SimpleRat(4,3),SimpleRat(1,1)), c * 2) assert_equal(Complex(SimpleRat(1,3),SimpleRat(1,4)), c / 2) assert_equal(Complex(SimpleRat(7,36),SimpleRat(2,3)), c ** 2) - assert_raise(NoMethodError){c <=> 2} + assert_nil(c <=> 2) assert_equal(Complex(SimpleRat(8,3),SimpleRat(1,2)), 2 + c) assert_equal(Complex(SimpleRat(4,3),SimpleRat(-1,2)), 2 - c) @@ -110,7 +111,7 @@ class ComplexRational_Test < Test::Unit::TestCase r = 2 ** c assert_in_delta(1.4940, r.real, 0.001) assert_in_delta(0.5392, r.imag, 0.001) - assert_raise(NoMethodError){2 <=> c} + assert_nil(2 <=> c) assert_equal(Complex(SimpleRat(13,6),SimpleRat(5,2)), c + cc) assert_equal(Complex(SimpleRat(-5,6),SimpleRat(-3,2)), c - cc) @@ -119,7 +120,7 @@ class ComplexRational_Test < Test::Unit::TestCase r = c ** cc assert_in_delta(0.1732, r.real, 0.001) assert_in_delta(0.1186, r.imag, 0.001) - assert_raise(NoMethodError){c <=> cc} + assert_nil(c <=> cc) assert_equal(Complex(SimpleRat(13,6),SimpleRat(5,2)), cc + c) assert_equal(Complex(SimpleRat(5,6),SimpleRat(3,2)), cc - c) @@ -128,7 +129,7 @@ class ComplexRational_Test < Test::Unit::TestCase r = cc ** c assert_in_delta(0.5498, r.real, 0.001) assert_in_delta(1.0198, r.imag, 0.001) - assert_raise(NoMethodError){cc <=> c} + assert_nil(cc <=> c) assert_equal([SimpleRat,SimpleRat], (+c).instance_eval{[real.class, imag.class]}) @@ -213,10 +214,10 @@ class SimpleRat < Numeric def numerator() @num end def denominator() @den end - def +@ () self end - def -@ () self.class.new(-@num, @den) end + def +@() self end + def -@() self.class.new(-@num, @den) end - def + (o) + def +(o) case o when SimpleRat, Rational a = @num * o.denominator @@ -232,7 +233,7 @@ class SimpleRat < Numeric end end - def - (o) + def -(o) case o when SimpleRat, Rational a = @num * o.denominator @@ -248,7 +249,7 @@ class SimpleRat < Numeric end end - def * (o) + def *(o) case o when SimpleRat, Rational a = @num * o.numerator @@ -272,7 +273,7 @@ class SimpleRat < Numeric self.class.new(a, b) when Integer if o == 0 - raise raise ZeroDivisionError, "divided by zero" + raise ZeroDivisionError, "divided by zero" end self.quo(self.class.new(o)) when Float @@ -333,7 +334,7 @@ class SimpleRat < Numeric def divmod(o) [div(o), modulo(o)] end def quotrem(o) [quot(o), remainder(o)] end - def ** (o) + def **(o) case o when SimpleRat, Rational Float(self) ** o @@ -356,7 +357,7 @@ class SimpleRat < Numeric end end - def <=> (o) + def <=>(o) case o when SimpleRat, Rational a = @num * o.denominator @@ -372,7 +373,7 @@ class SimpleRat < Numeric end end - def == (o) + def ==(o) begin (self <=> o) == 0 rescue |
