Skip to content

Commit

Permalink
Add checking foreign rrn API
Browse files Browse the repository at this point in the history
  • Loading branch information
0xd669 committed Dec 7, 2018
1 parent 93a903c commit b3bdff9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
14 changes: 13 additions & 1 deletion rrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,20 @@ def _is_sex_corresponding(rrn: str, female: bool) -> Optional[bool]:


def _is_foreignness_corresponding(rrn: str, foreign: bool) -> Optional[bool]:
f = is_foreign(rrn)
return f == foreign if f is not None else None


def is_foreign(rrn: str) -> Optional[bool]:
"""
Check if given RRN literal is foreigner or not.
It returns None when given RRN literal is too short to determine.
:param rrn: RRN literal
:return: expectation to be foreigner or not
"""
try:
return (5 <= int(rrn[SEX]) <= 8) == foreign
return 5 <= int(rrn[SEX]) <= 8
except IndexError:
return None

Expand Down
34 changes: 34 additions & 0 deletions tests/test_rrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,40 @@

class TestRRN(unittest.TestCase):

def test_is_foreign(self):
undetermined = None
foreign, domestic = True, False
for s, expected in [
('', undetermined),
('9', undetermined),
('94', undetermined),
('940', undetermined),
('9408', undetermined),
('94081', undetermined),
('940812', undetermined),
('9408120', domestic),
('94081201', domestic),
('9408121', domestic),
('94081212', domestic),
('9408122', domestic),
('94081223', domestic),
('9408123', domestic),
('94081234', domestic),
('9408124', domestic),
('94081245', domestic),
('9408125', foreign),
('94081256', foreign),
('9408126', foreign),
('94081267', foreign),
('9408127', foreign),
('94081278', foreign),
('9408128', foreign),
('94081289', foreign),
('9408129', domestic),
('94081290', domestic)
]:
self.assertEqual(expected, rrn.is_foreign(s))

def test_is_valid_rrn(self):
valid, invalid = True, False
for s, expected in [
Expand Down

0 comments on commit b3bdff9

Please sign in to comment.