mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
55cb1b5e70
commit
ed11f4b4b5
1 changed files with 3 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue