diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-06-04 21:41:02 -0700 |
---|---|---|
committer | Jeremy Evans <code@jeremyevans.net> | 2019-06-19 10:50:58 -0700 |
commit | b9ef35e4c6325864e013ab6e45df6fe00f759a47 (patch) | |
tree | 0e3814c316dd16034139a4b2802a69aca469da7c /test/ruby/test_complexrational.rb | |
parent | 65944e96d39a8ae3602751f49cb337335b2c6c45 (diff) | |
download | ruby-b9ef35e4c6325864e013ab6e45df6fe00f759a47.tar.gz |
Implement Complex#<=>
Implement Complex#<=> so that it is usable as an argument when
calling <=> on objects of other classes (since #coerce will coerce
such numbers to Complex). If the complex number has a zero imaginary
part, and the other argument is a real number (or complex number with
zero imaginary part), return -1, 0, or 1. Otherwise, return nil,
indicating the objects are not comparable.
Fixes [Bug #15857]
Diffstat (limited to 'test/ruby/test_complexrational.rb')
-rw-r--r-- | test/ruby/test_complexrational.rb | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/test/ruby/test_complexrational.rb b/test/ruby/test_complexrational.rb index 0360f5ee42..bf4e2b1809 100644 --- a/test/ruby/test_complexrational.rb +++ b/test/ruby/test_complexrational.rb @@ -102,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) @@ -111,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) @@ -120,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) @@ -129,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]}) |