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

ruby-changes:41458

From: nobu <ko1@a...>
Date: Thu, 14 Jan 2016 16:10:21 +0900 (JST)
Subject: [ruby-changes:41458] nobu:r53532 (trunk): test_sprintf.rb: simplify

nobu	2016-01-14 16:10:48 +0900 (Thu, 14 Jan 2016)

  New Revision: 53532

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

  Log:
    test_sprintf.rb: simplify
    
    * test/ruby/test_sprintf.rb (test_rational): enumerate formatted
      flags and simplify.

  Modified files:
    trunk/test/ruby/test_sprintf.rb
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 53531)
+++ test/ruby/test_sprintf.rb	(revision 53532)
@@ -156,10 +156,10 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_sprintf.rb#L156
     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

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

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