summaryrefslogtreecommitdiff
path: root/test/ruby/test_complexrational.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_complexrational.rb')
-rw-r--r--test/ruby/test_complexrational.rb43
1 files changed, 22 insertions, 21 deletions
diff --git a/test/ruby/test_complexrational.rb b/test/ruby/test_complexrational.rb
index 99f54e4e97..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)
@@ -74,8 +75,8 @@ class ComplexRational_Test < Test::Unit::TestCase
assert_equal(0, Rational(2,3) <=> SimpleRat(2,3))
assert_equal(0, SimpleRat(2,3) <=> Rational(2,3))
- assert(Rational(2,3) == SimpleRat(2,3))
- assert(SimpleRat(2,3) == Rational(2,3))
+ assert_equal(Rational(2,3), SimpleRat(2,3))
+ assert_equal(SimpleRat(2,3), Rational(2,3))
assert_equal(SimpleRat, (c + 0).class)
assert_equal(SimpleRat, (c - 0).class)
@@ -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]})
@@ -168,10 +169,10 @@ class ComplexRational_Test < Test::Unit::TestCase
assert_equal([Float,Float],
(cc ** c).instance_eval{[real.class, imag.class]})
- assert(Complex(SimpleRat(2,3),SimpleRat(3,2)) ==
- Complex(Rational(2,3),Rational(3,2)))
- assert(Complex(Rational(2,3),Rational(3,2)) ==
- Complex(SimpleRat(2,3),SimpleRat(3,2)))
+ assert_equal(Complex(SimpleRat(2,3),SimpleRat(3,2)),
+ Complex(Rational(2,3),Rational(3,2)))
+ assert_equal(Complex(Rational(2,3),Rational(3,2)),
+ Complex(SimpleRat(2,3),SimpleRat(3,2)))
assert_equal([SimpleRat,SimpleRat],
(c + 0).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