File: test_identification_ec.rb

package info (click to toggle)
ruby-ffaker 2.23.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,776 kB
  • sloc: ruby: 12,788; makefile: 8; sh: 1
file content (33 lines) | stat: -rw-r--r-- 692 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
33
# frozen_string_literal: true

require_relative 'helper'

class TestIdentificationEC < Test::Unit::TestCase
  include DeterministicHelper

  assert_methods_are_deterministic(FFaker::IdentificationEC, :ci)

  def setup
    @tester = FFaker::IdentificationEC
  end

  def test_ci
    assert_match(/^[0-9]{10}$/, @tester.ci)
  end

  def test_last_digit
    ci = @tester.ci
    sum = 0
    ci[0..8].chars.each_with_index do |char, index|
      if index.even?
        multiple = char.to_i * 2
        sum += multiple > 9 ? multiple - 9 : multiple
      else
        sum += char.to_i
      end
    end
    mod = sum % 10
    mod = 10 - mod if mod.positive?
    assert(ci[9].to_i == mod)
  end
end