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

ruby-changes:44408

From: nobu <ko1@a...>
Date: Mon, 24 Oct 2016 10:34:11 +0900 (JST)
Subject: [ruby-changes:44408] nobu:r56481 (trunk): refine assertions

nobu	2016-10-24 10:34:06 +0900 (Mon, 24 Oct 2016)

  New Revision: 56481

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

  Log:
    refine assertions
    
    * test/ruby/test_complex.rb, test/ruby/test_rational.rb: refine
      assertions for descriptive messages.

  Modified files:
    trunk/test/ruby/test_complex.rb
    trunk/test/ruby/test_rational.rb
Index: test/ruby/test_complex.rb
===================================================================
--- test/ruby/test_complex.rb	(revision 56480)
+++ test/ruby/test_complex.rb	(revision 56481)
@@ -41,10 +41,10 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L41
     c2 = Complex(0)
     c3 = Complex(1)
 
-    assert_equal(true, c.eql?(c2))
-    assert_equal(false, c.eql?(c3))
+    assert_operator(c, :eql?, c2)
+    assert_not_operator(c, :eql?, c3)
 
-    assert_equal(false, c.eql?(0))
+    assert_not_operator(c, :eql?, 0)
   end
 
   def test_hash
@@ -76,7 +76,7 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L76
   def test_freeze
     c = Complex(1)
     c.freeze
-    assert_equal(true, c.frozen?)
+    assert_predicate(c, :frozen?)
     assert_instance_of(String, c.to_s)
   end
 
@@ -189,14 +189,14 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L189
   def test_attr2
     c = Complex(1)
 
-    assert_equal(false, c.integer?)
-    assert_equal(false, c.real?)
+    assert_not_predicate(c, :integer?)
+    assert_not_predicate(c, :real?)
 
-    assert_equal(true, Complex(0).zero?)
-    assert_equal(true, Complex(0,0).zero?)
-    assert_equal(false, Complex(1,0).zero?)
-    assert_equal(false, Complex(0,1).zero?)
-    assert_equal(false, Complex(1,1).zero?)
+    assert_predicate(Complex(0), :zero?)
+    assert_predicate(Complex(0,0), :zero?)
+    assert_not_predicate(Complex(1,0), :zero?)
+    assert_not_predicate(Complex(0,1), :zero?)
+    assert_not_predicate(Complex(1,1), :zero?)
 
     assert_equal(nil, Complex(0).nonzero?)
     assert_equal(nil, Complex(0,0).nonzero?)
@@ -748,35 +748,35 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L748
 
   def test_respond
     c = Complex(1,1)
-    assert_equal(false, c.respond_to?(:%))
-    assert_equal(false, c.respond_to?(:<))
-    assert_equal(false, c.respond_to?(:<=))
-    assert_equal(false, c.respond_to?(:<=>))
-    assert_equal(false, c.respond_to?(:>))
-    assert_equal(false, c.respond_to?(:>=))
-    assert_equal(false, c.respond_to?(:between?))
-    assert_equal(false, c.respond_to?(:clamp))
-    assert_equal(false, c.respond_to?(:div))
-    assert_equal(false, c.respond_to?(:divmod))
-    assert_equal(false, c.respond_to?(:floor))
-    assert_equal(false, c.respond_to?(:ceil))
-    assert_equal(false, c.respond_to?(:modulo))
-    assert_equal(false, c.respond_to?(:remainder))
-    assert_equal(false, c.respond_to?(:round))
-    assert_equal(false, c.respond_to?(:step))
-    assert_equal(false, c.respond_to?(:tunrcate))
-
-    assert_equal(false, c.respond_to?(:positive?))
-    assert_equal(false, c.respond_to?(:negative?))
-    assert_equal(false, c.respond_to?(:sign))
-
-    assert_equal(false, c.respond_to?(:quotient))
-    assert_equal(false, c.respond_to?(:quot))
-    assert_equal(false, c.respond_to?(:quotrem))
-
-    assert_equal(false, c.respond_to?(:gcd))
-    assert_equal(false, c.respond_to?(:lcm))
-    assert_equal(false, c.respond_to?(:gcdlcm))
+    assert_not_respond_to(c, :%)
+    assert_not_respond_to(c, :<)
+    assert_not_respond_to(c, :<=)
+    assert_not_respond_to(c, :<=>)
+    assert_not_respond_to(c, :>)
+    assert_not_respond_to(c, :>=)
+    assert_not_respond_to(c, :between?)
+    assert_not_respond_to(c, :clamp)
+    assert_not_respond_to(c, :div)
+    assert_not_respond_to(c, :divmod)
+    assert_not_respond_to(c, :floor)
+    assert_not_respond_to(c, :ceil)
+    assert_not_respond_to(c, :modulo)
+    assert_not_respond_to(c, :remainder)
+    assert_not_respond_to(c, :round)
+    assert_not_respond_to(c, :step)
+    assert_not_respond_to(c, :tunrcate)
+
+    assert_not_respond_to(c, :positive?)
+    assert_not_respond_to(c, :negative?)
+    assert_not_respond_to(c, :sign)
+
+    assert_not_respond_to(c, :quotient)
+    assert_not_respond_to(c, :quot)
+    assert_not_respond_to(c, :quotrem)
+
+    assert_not_respond_to(c, :gcd)
+    assert_not_respond_to(c, :lcm)
+    assert_not_respond_to(c, :gcdlcm)
   end
 
   def test_to_i
@@ -852,8 +852,8 @@ class Complex_Test < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/ruby/test_complex.rb#L852
   end
 
   def test_supp
-    assert_equal(true, 1.real?)
-    assert_equal(true, 1.1.real?)
+    assert_predicate(1, :real?)
+    assert_predicate(1.1, :real?)
 
     assert_equal(1, 1.real)
     assert_equal(0, 1.imag)
Index: test/ruby/test_rational.rb
===================================================================
--- test/ruby/test_rational.rb	(revision 56480)
+++ test/ruby/test_rational.rb	(revision 56481)
@@ -35,10 +35,10 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L35
     c2 = Rational(0)
     c3 = Rational(1)
 
-    assert_equal(true, c.eql?(c2))
-    assert_equal(false, c.eql?(c3))
+    assert_operator(c, :eql?, c2)
+    assert_not_operator(c, :eql?, c3)
 
-    assert_equal(false, c.eql?(0))
+    assert_not_operator(c, :eql?, 0)
   end
 
   def test_hash
@@ -60,7 +60,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L60
   def test_freeze
     c = Rational(1)
     c.freeze
-    assert_equal(true, c.frozen?)
+    assert_predicate(c, :frozen?)
     assert_instance_of(String, c.to_s)
   end
 
@@ -161,15 +161,15 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L161
   def test_attr2
     c = Rational(1)
 
-    assert_equal(false, c.integer?)
-    assert_equal(true, c.real?)
+    assert_not_predicate(c, :integer?)
+    assert_predicate(c, :real?)
 
-    assert_equal(true, Rational(0).zero?)
-    assert_equal(true, Rational(0,1).zero?)
-    assert_equal(false, Rational(1,1).zero?)
+    assert_predicate(Rational(0), :zero?)
+    assert_predicate(Rational(0,1), :zero?)
+    assert_not_predicate(Rational(1,1), :zero?)
 
-    assert_equal(nil, Rational(0).nonzero?)
-    assert_equal(nil, Rational(0,1).nonzero?)
+    assert_nil(Rational(0).nonzero?)
+    assert_nil(Rational(0,1).nonzero?)
     assert_equal(Rational(1,1), Rational(1,1).nonzero?)
   end
 
@@ -537,23 +537,23 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L537
     assert_equal(-1, Rational(b-1) <=> Rational(b))
     assert_equal(+1, Rational(b) <=> Rational(b-1))
 
-    assert_equal(false, Rational(0) < Rational(0))
-    assert_equal(true, Rational(0) <= Rational(0))
-    assert_equal(true, Rational(0) >= Rational(0))
-    assert_equal(false, Rational(0) > Rational(0))
+    assert_not_operator(Rational(0), :<, Rational(0))
+    assert_operator(Rational(0), :<=, Rational(0))
+    assert_operator(Rational(0), :>=, Rational(0))
+    assert_not_operator(Rational(0), :>, Rational(0))
 
-    assert_equal(nil, Rational(0) <=> nil)
-    assert_equal(nil, Rational(0) <=> 'foo')
+    assert_nil(Rational(0) <=> nil)
+    assert_nil(Rational(0) <=> 'foo')
   end
 
   def test_eqeq
     assert_equal(Rational(1,1), Rational(1))
     assert_equal(Rational(-1,1), Rational(-1))
 
-    assert_equal(false, Rational(2,1) == Rational(1))
-    assert_equal(true, Rational(2,1) != Rational(1))
-    assert_equal(false, Rational(1) == nil)
-    assert_equal(false, Rational(1) == '')
+    assert_not_operator(Rational(2,1), :==, Rational(1))
+    assert_operator(Rational(2,1), :!=, Rational(1))
+    assert_not_operator(Rational(1), :==, nil)
+    assert_not_operator(Rational(1), :==, '')
   end
 
   def test_coerce
@@ -869,8 +869,8 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L869
   end
 
   def test_supp
-    assert_equal(true, 1.real?)
-    assert_equal(true, 1.1.real?)
+    assert_predicate(1, :real?)
+    assert_predicate(1.1, :real?)
 
     assert_equal(1, 1.numerator)
     assert_equal(9, 9.numerator)

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

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