Project

General

Profile

Feature #12484 ยป test_rational.rb.patch

mrkn (Kenta Murata), 06/13/2016 03:36 PM

View differences:

test/ruby/test_rational.rb
1 1
# frozen_string_literal: false
2 2
require 'test/unit'
3
require '-test-/integer'
3 4

  
4 5
class RationalSub < Rational; end
5 6

  
6 7
class Rational_Test < Test::Unit::TestCase
7 8

  
9
  def test_new
10
    assert_raise(TypeError) { Rational(Object.new) }
11
    assert_raise(TypeError) { Rational(1, Object.new) }
12

  
13
    class << (o = Object.new)
14
      alias to_int object_id
15
    end
16

  
17
    assert_raise(TypeError) { Rational(o) }
18
    assert_raise(TypeError) { Rational(1, o) }
19

  
20
    class << (o = Object.new)
21
      def to_r
22
        1/2r
23
      end
24
    end
25

  
26
    assert_equal(1/2r, Rational(o))
27
    assert_raise(TypeError) { Rational(1, o) }
28

  
29
    Rational(Bug::Integer::MyInteger.new)
30
  end
31

  
8 32
  def test_ratsub
9 33
    c = RationalSub.__send__(:convert, 1)
10 34