Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class MyNumberValidator
def validate(num)
# write your code here...
end
end
require './mynumber_validator'
RSpec.describe MyNumberValidator do
let(:validator) { MyNumberValidator.new }
describe '#validate_mynumber' do
subject { validator.validate(num) }
context 'pass the number that has invalid length ' do
let(:num) { 12345678901 }
it { is_expected.to be false }
end
context 'pass the invalid number' do
let(:num) { 123456789012 }
it { is_expected.to be false }
end
context 'pass the valid number' do
let(:num) { 123456789018 }
it { is_expected.to be true }
end
context 'pass the invalid number that calculated digit is bigger' do
let(:num) { 123456789001 }
it { is_expected.to be false }
end
context 'pass the valid number that calculated digit is bigger' do
let(:num) { 123456789000 }
it { is_expected.to be true }
end
context 'pass the invalid number as string' do
let(:num) { '123456789012' }
it { is_expected.to be false }
end
context 'pass the valid number starts with 0' do
let(:num) { '023456789013' }
it { is_expected.to be true }
end
end
end

Check Digit of MyNumber

How to calculate the check digit of mynumber

\begin{align*} d &= 11 - \Biggl( \sum^{11}{n=1} P_n \times Q_n \Biggr) \bmod 11 \ & \text{ただし,$\Biggl( \sum^{11}{n=1} P_n \times Q_n \Biggr) \bmod 11 \leq 1$の場合は$d=0$} \ P_n &= \text{ 個人番号を構成する検査用数字以外の十一桁の番号の最下位の桁を1桁目としたときの$n$桁目の数字} \ Q_n &= \begin{cases} n + 1 && \text{if $1 \leq n \leq 6$} \ n - 5 && \text{if $7 \leq n \leq 11$} \end{cases} \end{align*}

from: 総務省令第八十五号 行政手続における特定の個人を識別するための番号の利用等に関する法律

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment