-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve casino bet amount parser
- Loading branch information
Showing
5 changed files
with
83 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "duck-duck-bot" | ||
version = "1.18.11" | ||
version = "1.18.12" | ||
description = "" | ||
authors = ["Eldos <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,23 @@ | ||
__all__ = ('int_gaps',) | ||
__all__ = ('int_gaps', 'parse_abbreviated_number') | ||
|
||
|
||
def int_gaps(number: str | int) -> str: | ||
return f'{number:_}'.replace('_', ' ') | ||
|
||
|
||
def parse_abbreviated_number(number: str) -> int: | ||
if not number: | ||
raise ValueError('Number is empty') | ||
|
||
if not number[0].isdigit(): | ||
raise ValueError('Number does not start with a digit') | ||
|
||
abbreviations_and_values = ( | ||
('k', '000'), | ||
('к', '000'), | ||
) | ||
for abbreviation, value in abbreviations_and_values: | ||
if abbreviation in number: | ||
number = number.replace(abbreviation, value) | ||
|
||
return int(number) |
38 changes: 38 additions & 0 deletions
38
tests/test_services/test_text/test_parse_abbreviated_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import pytest | ||
|
||
from services.text import parse_abbreviated_number | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'number, expected', | ||
[ | ||
('1k', 1_000), | ||
('1к', 1_000), | ||
('1кк', 1_000_000), | ||
('1kk', 1_000_000), | ||
('10kk', 10_000_000), | ||
], | ||
) | ||
def test_parse_abbreviated_number(number, expected): | ||
assert parse_abbreviated_number(number) == expected | ||
|
||
|
||
def test_parse_abbreviated_number_empty(): | ||
with pytest.raises(ValueError) as error: | ||
parse_abbreviated_number('') | ||
assert str(error.value) == 'Number is empty' | ||
|
||
|
||
@pytest.mark.parametrize( | ||
'number', | ||
[ | ||
'k1', | ||
'к1', | ||
'k', | ||
'к', | ||
], | ||
) | ||
def test_parse_abbreviated_number_not_start_with_digit(number): | ||
with pytest.raises(ValueError) as error: | ||
parse_abbreviated_number(number) | ||
assert str(error.value) == 'Number does not start with a digit' |