aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/core_ext/integer_ext_test.rb
diff options
context:
space:
mode:
authorNicholas Seckar <nseckar@gmail.com>2005-07-19 12:58:01 +0000
committerNicholas Seckar <nseckar@gmail.com>2005-07-19 12:58:01 +0000
commit42723e3a0c74e25c45c0f763740a3115302da4ac (patch)
treef01b1d6c055a6b3051945f2aa4c23268e2dc32f6 /activesupport/test/core_ext/integer_ext_test.rb
parent83e2f6ae1e1d4c6863b7c0514d55d7641fbd7513 (diff)
downloadrails-42723e3a0c74e25c45c0f763740a3115302da4ac.tar.gz
rails-42723e3a0c74e25c45c0f763740a3115302da4ac.tar.bz2
rails-42723e3a0c74e25c45c0f763740a3115302da4ac.zip
Factor Fixnum and Bignum extensions into Integer class
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1863 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/test/core_ext/integer_ext_test.rb')
-rw-r--r--activesupport/test/core_ext/integer_ext_test.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/integer_ext_test.rb b/activesupport/test/core_ext/integer_ext_test.rb
new file mode 100644
index 0000000000..4435bc79d3
--- /dev/null
+++ b/activesupport/test/core_ext/integer_ext_test.rb
@@ -0,0 +1,38 @@
+require 'test/unit'
+require File.dirname(__FILE__) + '/../../lib/active_support/core_ext/integer'
+
+class IntegerExtTest < Test::Unit::TestCase
+ def test_even
+ assert [ -2, 0, 2, 4 ].all? { |i| i.even? }
+ assert ![ -1, 1, 3 ].all? { |i| i.even? }
+
+ assert 22953686867719691230002707821868552601124472329079.odd?
+ assert !22953686867719691230002707821868552601124472329079.even?
+ assert 22953686867719691230002707821868552601124472329080.even?
+ assert !22953686867719691230002707821868552601124472329080.odd?
+ end
+
+ def test_odd
+ assert ![ -2, 0, 2, 4 ].all? { |i| i.odd? }
+ assert [ -1, 1, 3 ].all? { |i| i.odd? }
+ assert 1000000000000000000000000000000000000000000000000000000001.odd?
+ end
+
+ def test_multiple_of
+ [ -7, 0, 7, 14 ].each { |i| assert i.multiple_of?(7) }
+ [ -7, 7, 14 ].each { |i| assert ! i.multiple_of?(6) }
+ # test with a prime
+ assert !22953686867719691230002707821868552601124472329079.multiple_of?(2)
+ assert !22953686867719691230002707821868552601124472329079.multiple_of?(3)
+ assert !22953686867719691230002707821868552601124472329079.multiple_of?(5)
+ assert !22953686867719691230002707821868552601124472329079.multiple_of?(7)
+ end
+
+ def test_ordinalize
+ # These tests are mostly just to ensure that the ordinalize method exists
+ # It's results are tested comprehensively in the inflector test cases.
+ assert_equal '1st', 1.ordinalize
+ assert_equal '8th', 8.ordinalize
+ 1000000000000000000000000000000000000000000000000000000000000000000000.ordinalize
+ end
+end