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
# frozen_string_literal: false
require 'test/unit'
require '-test-/integer'
class RationalSub < Rational; end
class Rational_Test < Test::Unit::TestCase
def test_new
assert_raise(TypeError) { Rational(Object.new) }
assert_raise(TypeError) { Rational(1, Object.new) }
class << (o = Object.new)
alias to_int object_id
end
assert_raise(TypeError) { Rational(o) }
assert_raise(TypeError) { Rational(1, o) }
class << (o = Object.new)
def to_r
1/2r
end
end
assert_equal(1/2r, Rational(o))
assert_raise(TypeError) { Rational(1, o) }
Rational(Bug::Integer::MyInteger.new)
end
def test_ratsub
c = RationalSub.__send__(:convert, 1)
(7-7/7)