mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* test/ruby/test_sprintf.rb: added tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5763 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
953caaf959
commit
44284f71c9
3 changed files with 82 additions and 0 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Wed Feb 18 18:07:09 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* test/ruby/test_sprintf.rb: added tests.
|
||||||
|
|
||||||
Wed Feb 18 17:18:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
|
Wed Feb 18 17:18:01 2004 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||||
|
|
||||||
* ext/win32ole/win32ole.c: need to include <olectl.h> on Cygwin.
|
* ext/win32ole/win32ole.c: need to include <olectl.h> on Cygwin.
|
||||||
|
|
1
MANIFEST
1
MANIFEST
|
@ -825,6 +825,7 @@ test/ruby/test_pipe.rb
|
||||||
test/ruby/test_proc.rb
|
test/ruby/test_proc.rb
|
||||||
test/ruby/test_range.rb
|
test/ruby/test_range.rb
|
||||||
test/ruby/test_signal.rb
|
test/ruby/test_signal.rb
|
||||||
|
test/ruby/test_sprintf.rb
|
||||||
test/ruby/test_stringchar.rb
|
test/ruby/test_stringchar.rb
|
||||||
test/ruby/test_struct.rb
|
test/ruby/test_struct.rb
|
||||||
test/ruby/test_system.rb
|
test/ruby/test_system.rb
|
||||||
|
|
77
test/ruby/test_sprintf.rb
Normal file
77
test/ruby/test_sprintf.rb
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
require 'test/unit'
|
||||||
|
|
||||||
|
$KCODE = 'none'
|
||||||
|
|
||||||
|
class TestSprintf < Test::Unit::TestCase
|
||||||
|
def test_binary
|
||||||
|
assert_equal("0", sprintf("%b", 0))
|
||||||
|
assert_equal("1", sprintf("%b", 1))
|
||||||
|
assert_equal("10", sprintf("%b", 2))
|
||||||
|
assert_equal("..1", sprintf("%b", -1))
|
||||||
|
|
||||||
|
assert_equal(" 0", sprintf("%4b", 0))
|
||||||
|
assert_equal(" 1", sprintf("%4b", 1))
|
||||||
|
assert_equal(" 10", sprintf("%4b", 2))
|
||||||
|
assert_equal(" ..1", sprintf("%4b", -1))
|
||||||
|
|
||||||
|
assert_equal("0000", sprintf("%04b", 0))
|
||||||
|
assert_equal("0001", sprintf("%04b", 1))
|
||||||
|
assert_equal("0010", sprintf("%04b", 2))
|
||||||
|
assert_equal("1111", sprintf("%04b", -1))
|
||||||
|
|
||||||
|
assert_equal("0000", sprintf("%.4b", 0))
|
||||||
|
assert_equal("0001", sprintf("%.4b", 1))
|
||||||
|
assert_equal("0010", sprintf("%.4b", 2))
|
||||||
|
assert_equal("1111", sprintf("%.4b", -1))
|
||||||
|
|
||||||
|
assert_equal(" 0000", sprintf("%6.4b", 0))
|
||||||
|
assert_equal(" 0001", sprintf("%6.4b", 1))
|
||||||
|
assert_equal(" 0010", sprintf("%6.4b", 2))
|
||||||
|
assert_equal(" 1111", sprintf("%6.4b", -1))
|
||||||
|
|
||||||
|
assert_equal(" 0b0", sprintf("%#4b", 0))
|
||||||
|
assert_equal(" 0b1", sprintf("%#4b", 1))
|
||||||
|
assert_equal("0b10", sprintf("%#4b", 2))
|
||||||
|
assert_equal("0b..1", sprintf("%#4b", -1))
|
||||||
|
|
||||||
|
assert_equal("0b00", sprintf("%#04b", 0))
|
||||||
|
assert_equal("0b01", sprintf("%#04b", 1))
|
||||||
|
assert_equal("0b10", sprintf("%#04b", 2))
|
||||||
|
assert_equal("0b11", sprintf("%#04b", -1))
|
||||||
|
|
||||||
|
assert_equal("0b0000", sprintf("%#.4b", 0))
|
||||||
|
assert_equal("0b0001", sprintf("%#.4b", 1))
|
||||||
|
assert_equal("0b0010", sprintf("%#.4b", 2))
|
||||||
|
assert_equal("0b1111", sprintf("%#.4b", -1))
|
||||||
|
|
||||||
|
assert_equal("0b0000", sprintf("%#6.4b", 0))
|
||||||
|
assert_equal("0b0001", sprintf("%#6.4b", 1))
|
||||||
|
assert_equal("0b0010", sprintf("%#6.4b", 2))
|
||||||
|
assert_equal("0b1111", sprintf("%#6.4b", -1))
|
||||||
|
|
||||||
|
assert_equal("+0", sprintf("%+b", 0))
|
||||||
|
assert_equal("+1", sprintf("%+b", 1))
|
||||||
|
assert_equal("+10", sprintf("%+b", 2))
|
||||||
|
assert_equal("-1", sprintf("%+b", -1))
|
||||||
|
|
||||||
|
assert_equal(" +0", sprintf("%+4b", 0))
|
||||||
|
assert_equal(" +1", sprintf("%+4b", 1))
|
||||||
|
assert_equal(" +10", sprintf("%+4b", 2))
|
||||||
|
assert_equal(" -1", sprintf("%+4b", -1))
|
||||||
|
|
||||||
|
assert_equal("+000", sprintf("%+04b", 0))
|
||||||
|
assert_equal("+001", sprintf("%+04b", 1))
|
||||||
|
assert_equal("+010", sprintf("%+04b", 2))
|
||||||
|
assert_equal("-001", sprintf("%+04b", -1))
|
||||||
|
|
||||||
|
assert_equal("+0000", sprintf("%+.4b", 0))
|
||||||
|
assert_equal("+0001", sprintf("%+.4b", 1))
|
||||||
|
assert_equal("+0010", sprintf("%+.4b", 2))
|
||||||
|
assert_equal("-0001", sprintf("%+.4b", -1))
|
||||||
|
|
||||||
|
assert_equal(" +0000", sprintf("%+6.4b", 0))
|
||||||
|
assert_equal(" +0001", sprintf("%+6.4b", 1))
|
||||||
|
assert_equal(" +0010", sprintf("%+6.4b", 2))
|
||||||
|
assert_equal(" -0001", sprintf("%+6.4b", -1))
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue