[前][次][番号順一覧][スレッド一覧]

ruby-changes:38440

From: nobu <ko1@a...>
Date: Sun, 17 May 2015 15:00:02 +0900 (JST)
Subject: [ruby-changes:38440] nobu:r50521 (trunk): test_numeric.rb: separate dummy classes

nobu	2015-05-17 14:59:58 +0900 (Sun, 17 May 2015)

  New Revision: 50521

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50521

  Log:
    test_numeric.rb: separate dummy classes
    
    * test/ruby/test_numeric.rb: use separate dummy classes for each
      test cases.

  Modified files:
    trunk/test/ruby/test_numeric.rb
Index: test/ruby/test_numeric.rb
===================================================================
--- test/ruby/test_numeric.rb	(revision 50520)
+++ test/ruby/test_numeric.rb	(revision 50521)
@@ -1,9 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L1
 require 'test/unit'
 
 class TestNumeric < Test::Unit::TestCase
-  class DummyNumeric < Numeric
-  end
-
   def test_coerce
     a, b = 1.coerce(2)
     assert_equal(Fixnum, a.class)
@@ -39,50 +36,39 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L36
   end
 
   def test_dummynumeric
-    a = DummyNumeric.new
-
-    DummyNumeric.class_eval do
+    a = Class.new(Numeric) do
       def coerce(x); nil; end
-    end
+    end.new
     assert_raise(TypeError) { -a }
     assert_nil(1 <=> a)
     assert_raise(ArgumentError) { 1 <= a }
 
-    DummyNumeric.class_eval do
-      remove_method :coerce
+    a = Class.new(Numeric) do
       def coerce(x); 1.coerce(x); end
-    end
+    end.new
     assert_equal(2, 1 + a)
     assert_equal(0, 1 <=> a)
     assert_operator(1, :<=, a)
 
-    DummyNumeric.class_eval do
-      remove_method :coerce
+    a = Class.new(Numeric) do
       def coerce(x); [x, 1]; end
-    end
+    end.new
     assert_equal(-1, -a)
 
     bug7688 = '[ruby-core:51389] [Bug #7688]'
-    DummyNumeric.class_eval do
-      remove_method :coerce
+    a = Class.new(Numeric) do
       def coerce(x); raise StandardError; end
-    end
+    end.new
     assert_raise_with_message(TypeError, /can't be coerced into /) { 1 + a }
     warn = /will no more rescue exceptions of #coerce.+ in the next release/m
     assert_warn(warn, bug7688) { assert_raise(ArgumentError) { 1 < a } }
 
-    DummyNumeric.class_eval do
-      remove_method :coerce
+    a = Class.new(Numeric) do
       def coerce(x); :bad_return_value; end
-    end
+    end.new
     assert_raise_with_message(TypeError, "coerce must return [x, y]") { 1 + a }
     warn = /Bad return value for #coerce.+next release will raise an error/m
     assert_warn(warn, bug7688) { assert_raise(ArgumentError) { 1 < a } }
-
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :coerce
-    end
   end
 
   def test_singleton_method
@@ -102,42 +88,31 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L88
   end
 
   def test_quo
-    assert_raise(TypeError) {DummyNumeric.new.quo(1)}
+    a = Numeric.new
+    assert_raise(TypeError) {a.quo(1)}
   end
 
   def test_quo_ruby_core_41575
-    x = DummyNumeric.new
     rat = 84.quo(1)
-    DummyNumeric.class_eval do
+    x = Class.new(Numeric) do
       define_method(:to_r) { rat }
-    end
+    end.new
     assert_equal(2.quo(1), x.quo(42), '[ruby-core:41575]')
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :to_r
-    end
   end
 
   def test_divmod
 =begin
-    DummyNumeric.class_eval do
+    x = Class.new(Numeric) do
       def /(x); 42.0; end
       def %(x); :mod; end
-    end
+    end.new
 
-    assert_equal(42, DummyNumeric.new.div(1))
-    assert_equal(:mod, DummyNumeric.new.modulo(1))
-    assert_equal([42, :mod], DummyNumeric.new.divmod(1))
+    assert_equal(42, x.div(1))
+    assert_equal(:mod, x.modulo(1))
+    assert_equal([42, :mod], x.divmod(1))
 =end
 
     assert_kind_of(Integer, 11.divmod(3.5).first, '[ruby-dev:34006]')
-
-=begin
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :/, :%
-    end
-=end
   end
 
   def test_real_p
@@ -149,51 +124,34 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L124
   end
 
   def test_abs
-    a = DummyNumeric.new
-    DummyNumeric.class_eval do
+    a = Class.new(Numeric) do
       def -@; :ok; end
       def <(x); true; end
-    end
+    end.new
 
     assert_equal(:ok, a.abs)
 
-    DummyNumeric.class_eval do
-      remove_method :<
+    a = Class.new(Numeric) do
       def <(x); false; end
-    end
+    end.new
 
     assert_equal(a, a.abs)
-
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :-@, :<
-    end
   end
 
   def test_zero_p
-    DummyNumeric.class_eval do
+    a = Class.new(Numeric) do
       def ==(x); true; end
-    end
+    end.new
 
-    assert_predicate(DummyNumeric.new, :zero?)
-
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :==
-    end
+    assert_predicate(a, :zero?)
   end
 
   def test_to_int
-    DummyNumeric.class_eval do
+    a = Class.new(Numeric) do
       def to_i; :ok; end
-    end
-
-    assert_equal(:ok, DummyNumeric.new.to_int)
+    end.new
 
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :to_i
-    end
+    assert_equal(:ok, a.to_int)
   end
 
   def test_cmp
@@ -203,42 +161,32 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L161
   end
 
   def test_floor_ceil_round_truncate
-    DummyNumeric.class_eval do
+    a = Class.new(Numeric) do
       def to_f; 1.5; end
-    end
+    end.new
 
-    a = DummyNumeric.new
     assert_equal(1, a.floor)
     assert_equal(2, a.ceil)
     assert_equal(2, a.round)
     assert_equal(1, a.truncate)
 
-    DummyNumeric.class_eval do
-      remove_method :to_f
+    a = Class.new(Numeric) do
       def to_f; 1.4; end
-    end
+    end.new
 
-    a = DummyNumeric.new
     assert_equal(1, a.floor)
     assert_equal(2, a.ceil)
     assert_equal(1, a.round)
     assert_equal(1, a.truncate)
 
-    DummyNumeric.class_eval do
-      remove_method :to_f
+    a = Class.new(Numeric) do
       def to_f; -1.5; end
-    end
+    end.new
 
-    a = DummyNumeric.new
     assert_equal(-2, a.floor)
     assert_equal(-1, a.ceil)
     assert_equal(-2, a.round)
     assert_equal(-1, a.truncate)
-
-  ensure
-    DummyNumeric.class_eval do
-      remove_method :to_f
-    end
   end
 
   def assert_step(expected, (from, *args), inf: false)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]