@@ -65,7 +65,7 @@ def test_freeze
6565 assert_instance_of ( String , c . to_s )
6666 end
6767
68- def test_conv
68+ def test_conv_integer
6969 c = Rational ( 0 , 1 )
7070 assert_equal ( Rational ( 0 , 1 ) , c )
7171
@@ -94,6 +94,11 @@ def test_conv
9494 c = Rational ( Rational ( 1 , 2 ) , Rational ( 1 , 2 ) )
9595 assert_equal ( Rational ( 1 ) , c )
9696
97+ assert_equal ( Rational ( 3 ) , Rational ( 3 ) )
98+ assert_equal ( Rational ( 1 ) , Rational ( 3 , 3 ) )
99+ end
100+
101+ def test_conv_complex
97102 c = Rational ( Complex ( 1 , 2 ) , 2 )
98103 assert_equal ( Complex ( Rational ( 1 , 2 ) , 1 ) , c )
99104
@@ -102,11 +107,21 @@ def test_conv
102107
103108 c = Rational ( Complex ( 1 , 2 ) , Complex ( 1 , 2 ) )
104109 assert_equal ( Rational ( 1 ) , c )
110+ end
105111
106- assert_equal ( Rational ( 3 ) , Rational ( 3 ) )
107- assert_equal ( Rational ( 1 ) , Rational ( 3 , 3 ) )
112+ def test_conv_float
108113 assert_equal ( 3.3 . to_r , Rational ( 3.3 ) )
109114 assert_equal ( 1 , Rational ( 3.3 , 3.3 ) )
115+
116+ if ( 0.0 /0 ) . nan?
117+ assert_raise ( FloatDomainError ) { Rational ( 0.0 /0 ) }
118+ end
119+ if ( 1.0 /0 ) . infinite?
120+ assert_raise ( FloatDomainError ) { Rational ( 1.0 /0 ) }
121+ end
122+ end
123+
124+ def test_conv_string
110125 assert_equal ( Rational ( 3 ) , Rational ( '3' ) )
111126 assert_equal ( Rational ( 1 ) , Rational ( '3.0' , '3.0' ) )
112127 assert_equal ( Rational ( 1 ) , Rational ( '3/3' , '3/3' ) )
@@ -115,6 +130,9 @@ def test_conv
115130 assert_equal ( Rational ( 111 , 10 ) , Rational ( '1.11e1' ) )
116131 assert_equal ( Rational ( 111 , 100 ) , Rational ( '1.11e0' ) )
117132 assert_equal ( Rational ( 111 , 1000 ) , Rational ( '1.11e-1' ) )
133+ end
134+
135+ def test_conv_error
118136 assert_raise ( TypeError ) { Rational ( nil ) }
119137 assert_raise ( ArgumentError ) { Rational ( '' ) }
120138
@@ -131,7 +149,9 @@ def test_conv
131149 assert_raise ( TypeError ) { Rational ( Object . new ) }
132150 assert_raise ( TypeError ) { Rational ( Object . new , Object . new ) }
133151 assert_raise ( TypeError ) { Rational ( 1 , Object . new ) }
152+ end
134153
154+ def test_conv_coerce
135155 bug12485 = '[ruby-core:75995] [Bug #12485]'
136156 o = Object . new
137157 def o . to_int ; 1 ; end
@@ -163,13 +183,6 @@ def o.to_r; raise; end
163183 assert_raise ( ArgumentError ) { Rational ( ) }
164184 assert_raise ( ArgumentError ) { Rational ( 1 , 2 , 3 ) }
165185
166- if ( 0.0 /0 ) . nan?
167- assert_raise ( FloatDomainError ) { Rational ( 0.0 /0 ) }
168- end
169- if ( 1.0 /0 ) . infinite?
170- assert_raise ( FloatDomainError ) { Rational ( 1.0 /0 ) }
171- end
172-
173186 bug16518 = "[ruby-core:96942] [Bug #16518]"
174187 cls = Class . new ( Numeric ) do
175188 def /( y ) ; 42 ; end
0 commit comments