diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-18 03:55:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-18 03:55:33 +0000 |
commit | 39f31b8c87dc28fd95f4e07194ecc2c491e05f6a (patch) | |
tree | 85f6ee800a80f8c10e8e60a46cd86e56b026df56 /test/ruby/test_integer.rb | |
parent | adc7cb240abea320c991430e98b633ad4e327e08 (diff) | |
download | ruby-39f31b8c87dc28fd95f4e07194ecc2c491e05f6a.tar.gz |
numeric.c: int_truncate
* numeric.c (int_truncate): add an optional parameter, digits, as
well as Integer#round. [Feature #12245]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_integer.rb')
-rw-r--r-- | test/ruby/test_integer.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 53268ea773..12ada1709e 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -249,6 +249,31 @@ class TestInteger < Test::Unit::TestCase assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).ceil(-1)) end + def test_truncate + assert_int_equal(11111, 11111.truncate) + assert_int_equal(11111, 11111.truncate(0)) + + assert_float_equal(11111.0, 11111.truncate(1)) + assert_float_equal(11111.0, 11111.truncate(2)) + + assert_int_equal(11110, 11110.truncate(-1)) + assert_int_equal(11110, 11119.truncate(-1)) + assert_int_equal(11100, 11100.truncate(-2)) + assert_int_equal(11100, 11199.truncate(-2)) + assert_int_equal(0, 11111.truncate(-5)) + assert_int_equal(+200, +299.truncate(-2)) + assert_int_equal(+300, +300.truncate(-2)) + assert_int_equal(-200, -299.truncate(-2)) + assert_int_equal(-300, -300.truncate(-2)) + assert_int_equal(+20 * 10**70, (+25 * 10**70).truncate(-71)) + assert_int_equal(-20 * 10**70, (-25 * 10**70).truncate(-71)) + assert_int_equal(+20 * 10**70, (+25 * 10**70 - 1).truncate(-71)) + assert_int_equal(-20 * 10**70, (-25 * 10**70 + 1).truncate(-71)) + + assert_int_equal(1111_1111_1111_1111_1111_1111_1111_1110, 1111_1111_1111_1111_1111_1111_1111_1111.truncate(-1)) + assert_int_equal(-1111_1111_1111_1111_1111_1111_1111_1110, (-1111_1111_1111_1111_1111_1111_1111_1111).truncate(-1)) + end + def test_bitwise_and_with_integer_mimic_object def (obj = Object.new).to_int 10 |