From 3bda73868f66e3cc24628a9dcce0568363ff2337 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 24 Oct 2016 01:34:06 +0000 Subject: [PATCH] refine assertions * test/ruby/test_complex.rb, test/ruby/test_rational.rb: refine assertions for descriptive messages. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56481 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_complex.rb | 78 +++++++++++++++++++------------------- test/ruby/test_rational.rb | 46 +++++++++++----------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb index 2f21c10b3a..7d4358c087 100644 --- a/test/ruby/test_complex.rb +++ b/test/ruby/test_complex.rb @@ -41,10 +41,10 @@ class Complex_Test < Test::Unit::TestCase 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::TestCase 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::TestCase 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::TestCase 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_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_equal(false, c.respond_to?(:positive?)) - assert_equal(false, c.respond_to?(:negative?)) - assert_equal(false, c.respond_to?(:sign)) + assert_not_respond_to(c, :positive?) + assert_not_respond_to(c, :negative?) + assert_not_respond_to(c, :sign) - assert_equal(false, c.respond_to?(:quotient)) - assert_equal(false, c.respond_to?(:quot)) - assert_equal(false, c.respond_to?(:quotrem)) + assert_not_respond_to(c, :quotient) + assert_not_respond_to(c, :quot) + assert_not_respond_to(c, :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, :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::TestCase 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) diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 1fa9ebe865..387f4121cf 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -35,10 +35,10 @@ class Rational_Test < Test::Unit::TestCase 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::TestCase 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::TestCase 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::TestCase 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::TestCase 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)