1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/ruby/test_sprintf.rb
nahi 994dfc0ae6 * test/*: should not depend on $KCODE.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5764 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-02-18 13:08:08 +00:00

75 lines
2.6 KiB
Ruby

require 'test/unit'
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