File: integer_ext_test.rb

package info (click to toggle)
rails 2%3A5.2.2.1%2Bdfsg-1%2Bdeb10u3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 33,200 kB
  • sloc: ruby: 235,858; javascript: 20,695; yacc: 46; sql: 43; makefile: 22; sh: 14
file content (32 lines) | stat: -rw-r--r-- 877 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

require "abstract_unit"
require "active_support/core_ext/integer"

class IntegerExtTest < ActiveSupport::TestCase
  PRIME = 22953686867719691230002707821868552601124472329079

  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 the 0 edge case
    assert 0.multiple_of?(0)
    assert !5.multiple_of?(0)

    # test with a prime
    [2, 3, 5, 7].each { |i| assert !PRIME.multiple_of?(i) }
  end

  def test_ordinalize
    # These tests are mostly just to ensure that the ordinalize method exists.
    # Its results are tested comprehensively in the inflector test cases.
    assert_equal "1st", 1.ordinalize
    assert_equal "8th", 8.ordinalize
  end

  def test_ordinal
    assert_equal "st", 1.ordinal
    assert_equal "th", 8.ordinal
  end
end