Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change 'یکم' to 'اول' #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions persian_tools/digits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def to_word(num: int) -> str:

if number == 0:
return 'صفر'
elif number == 1:
return 'اول'

is_negative = number < 0
number = abs(number)
Expand Down
1 change: 1 addition & 0 deletions persian_tools/digits/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"هفت صد": "هفتصد",
"هشت صد": "هشتصد",
"نه صد": "نهصد",
"اول": "یک",
}

JOINERS = ["و", " و "]
Expand Down
4 changes: 4 additions & 0 deletions persian_tools/ordinal_suffix.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
def add(number: str) -> str:
if number == 'یک':
return "اول"
if number.endswith('ی'):
return number + ' اُم'
if number.endswith('سه'):
Expand All @@ -13,6 +15,8 @@ def remove(word: str) -> str:

if word.endswith('سوم'):
return word[:-3] + 'سه'
elif word in ['اول', 'اولین']:
return "یک"
elif word.endswith('م'):
return word[:-1]
return word
10 changes: 10 additions & 0 deletions tests/test_digis.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def test_convert_to_word():
assert digits.convert_to_word(-123, ordinal=True) == 'منفی صد و بیست و سوم'
assert digits.convert_to_word(33, ordinal=True) == 'سی و سوم'
assert digits.convert_to_word(45, ordinal=True) == 'چهل و پنجم'
assert digits.convert_to_word(1, ordinal=True) == 'اول'
assert digits.convert_to_word(41, ordinal=True) == 'چهل و یکم'
assert digits.convert_to_word(101, ordinal=True) == 'صد و یکم'


def test_convert_from_word():
Expand Down Expand Up @@ -79,3 +82,10 @@ def test_convert_from_word_with_ordinal():
assert len(str(digits.convert_from_word("منفی سه هزارمین"))) == 5
assert digits.convert_from_word("منفی سی اُم") == -30
assert digits.convert_from_word("سی و سوم") == 33
assert digits.convert_from_word("سی و یکم") == 31
assert digits.convert_from_word("سی و یکمین") == 31
assert digits.convert_from_word("اول") == 1
assert digits.convert_from_word("اولین") == 1
assert digits.convert_from_word("یکمین") == 1


5 changes: 5 additions & 0 deletions tests/test_ordinal_suffix.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ def test_add_ordinal_suffix():
assert ordinal_suffix.add('چهل و سه') == 'چهل و سوم'
assert ordinal_suffix.add('چهل و پنج') == 'چهل و پنجم'
assert ordinal_suffix.add('سی') == 'سی اُم'
assert ordinal_suffix.add('یک') == 'اول'
assert ordinal_suffix.add('چهل و یک') == 'چهل و یکم'


def test_remove_ordinal_suffix():
assert ordinal_suffix.remove('چهل و سوم') == 'چهل و سه'
assert ordinal_suffix.remove('چهل و پنجم') == 'چهل و پنج'
assert ordinal_suffix.remove('سی اُم') == 'سی'
assert ordinal_suffix.remove('اول') == 'یک'
assert ordinal_suffix.remove('یکم') == 'یک'
assert ordinal_suffix.remove('چهل و یکم') == 'چهل و یک'