From ed11f4b4b5fbc3ae059cab582f054518f60f9e74 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 14 Jan 2016 07:10:48 +0000 Subject: [PATCH] test_sprintf.rb: simplify * test/ruby/test_sprintf.rb (test_rational): enumerate formatted flags and simplify. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53532 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_sprintf.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb index 1d3badddf9..714ef8b4e2 100644 --- a/test/ruby/test_sprintf.rb +++ b/test/ruby/test_sprintf.rb @@ -156,10 +156,10 @@ class TestSprintf < Test::Unit::TestCase assert_match(/\A0\.3+\z/, sprintf("%.60f", 1/3r)) assert_match(/\A1\.20+\z/, sprintf("%.60f", 1.2r)) - 0.upto(9) do |len| - -1.upto(9) do |prec| + ["", *"0".."9"].each do |len| + ["", *".0"..".9"].each do |prec| ['', '+', '-', ' ', '0', '+0', '-0', ' 0', '+ ', '- ', '+ 0', '- 0'].each do |flags| - fmt = "%#{flags}#{len > 0 ? len : ''}#{prec >= 0 ? ".#{prec}" : ''}f" + fmt = "%#{flags}#{len}#{prec}f" [0, 0.1, 0.01, 0.001, 1.001, 100.0, 100.001, 10000000000.0, 0.00000000001, 1/3r, 2/3r, 1.2r, 10r].each do |num| assert_equal(sprintf(fmt, num.to_f), sprintf(fmt, num.to_r), "sprintf(#{fmt.inspect}, #{num.inspect}.to_r)") assert_equal(sprintf(fmt, -num.to_f), sprintf(fmt, -num.to_r), "sprintf(#{fmt.inspect}, #{(-num).inspect}.to_r)") if num > 0