Sha256: 27adb481aea78ee6cf74cbc61cda1ce91e4f825e648d1c66c86e442b5a02539b

Contents?: true

Size: 1.47 KB

Versions: 69

Compression:

Stored size: 1.47 KB

Contents

require File.dirname(__FILE__) + '/../abstract_unit'

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

Version data entries

69 entries across 69 versions & 3 rubygems

Version Path
backlog-0.0.0 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.0.1 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.0.2 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.0.4 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.0.5 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.1.1 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.1.0 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.1.2 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.2.0 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.2.1 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.0 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.2 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.1 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.3 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.4 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.5 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.6 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.7 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.8 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb
backlog-0.3.9 vendor/rails/activesupport/test/core_ext/integer_ext_test.rb