mirror of
https://github.com/bblaz/num2words.git
synced 2025-12-06 06:42:25 +00:00
Merge branch 'master' into strings
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
@@ -13,7 +14,6 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
# from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
@@ -1,5 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from decimal import Decimal
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@@ -22,7 +23,10 @@ from num2words import num2words
|
||||
|
||||
|
||||
class Num2WordsDETest(TestCase):
|
||||
|
||||
def test_ordinal_less_than_twenty(self):
|
||||
self.assertEqual(num2words(0, ordinal=True, lang='de'), "nullte")
|
||||
self.assertEqual(num2words(1, ordinal=True, lang='de'), "erste")
|
||||
self.assertEqual(num2words(7, ordinal=True, lang='de'), "siebte")
|
||||
self.assertEqual(num2words(8, ordinal=True, lang='de'), "achte")
|
||||
self.assertEqual(num2words(12, ordinal=True, lang='de'), "zwölfte")
|
||||
@@ -44,17 +48,28 @@ class Num2WordsDETest(TestCase):
|
||||
num2words(4000, ordinal=True, lang='de'), "viertausendste"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(2000000, ordinal=True, lang='de'), "zwei millionste"
|
||||
num2words(1000000, ordinal=True, lang='de'), "millionste"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(2000000, ordinal=True, lang='de'), "zweimillionste"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000000000, ordinal=True, lang='de'), "milliardste"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(5000000000, ordinal=True, lang='de'),
|
||||
"fünf milliardste"
|
||||
"fünfmilliardste"
|
||||
)
|
||||
|
||||
def test_cardinal_at_some_numbers(self):
|
||||
self.assertEqual(num2words(2000000, lang='de'), "zwei millionen")
|
||||
self.assertEqual(num2words(4000000000, lang='de'), "vier milliarden")
|
||||
self.assertEqual(num2words(1000000000, lang='de'), "eine milliarde")
|
||||
self.assertEqual(num2words(100, lang='de'), "einhundert")
|
||||
self.assertEqual(num2words(1000, lang='de'), "eintausend")
|
||||
self.assertEqual(num2words(5000, lang='de'), "fünftausend")
|
||||
self.assertEqual(num2words(10000, lang='de'), "zehntausend")
|
||||
self.assertEqual(num2words(1000000, lang='de'), "eine Million")
|
||||
self.assertEqual(num2words(2000000, lang='de'), "zwei Millionen")
|
||||
self.assertEqual(num2words(4000000000, lang='de'), "vier Milliarden")
|
||||
self.assertEqual(num2words(1000000000, lang='de'), "eine Milliarde")
|
||||
|
||||
def test_cardinal_for_decimal_number(self):
|
||||
self.assertEqual(
|
||||
@@ -64,8 +79,8 @@ class Num2WordsDETest(TestCase):
|
||||
def test_giant_cardinal_for_merge(self):
|
||||
self.assertEqual(
|
||||
num2words(4500072900000111, lang='de'),
|
||||
"vier billiarden fünfhundert billionen " +
|
||||
"zweiundsiebzig milliarden neunhundert millionen hundertelf"
|
||||
"vier Billiarden fünfhundert Billionen " +
|
||||
"zweiundsiebzig Milliarden neunhundert Millionen einhundertelf"
|
||||
)
|
||||
|
||||
def test_ordinal_num(self):
|
||||
@@ -79,12 +94,28 @@ class Num2WordsDETest(TestCase):
|
||||
self.assertRaises(TypeError, num2words, 2.453, ordinal=True, lang='de')
|
||||
|
||||
def test_currency(self):
|
||||
self.assertEqual(num2words(12.00, to='currency', lang='de'),
|
||||
'zwölf euro')
|
||||
self.assertEqual(num2words(1, lang='de', to='currency'),
|
||||
'ein Euro')
|
||||
self.assertEqual(num2words(12, lang='de', to='currency'),
|
||||
'zwölf Euro')
|
||||
self.assertEqual(num2words(12.00, lang='de', to='currency'),
|
||||
'zwölf Euro')
|
||||
self.assertEqual(num2words(100.0, lang='de', to='currency'),
|
||||
"einhundert Euro")
|
||||
self.assertEqual(num2words(190, lang='de', to='currency'),
|
||||
"einhundertneunzig Euro")
|
||||
self.assertEqual(num2words(1.90, lang='de', to='currency'),
|
||||
"ein Euro und neunzig Cent")
|
||||
self.assertEqual(num2words(3.4, lang='de', to='currency'),
|
||||
"drei Euro und vierzig Cent")
|
||||
self.assertEqual(num2words(20.18, lang='de', to='currency'),
|
||||
"zwanzig Euro und achtzehn Cent")
|
||||
self.assertEqual(num2words(3.04, lang='de', to='currency'),
|
||||
"drei Euro und vier Cent")
|
||||
|
||||
def test_old_currency(self):
|
||||
self.assertEqual(num2words(12.00, to='currency', lang='de', old=True),
|
||||
'zwölf mark')
|
||||
'zwölf Mark')
|
||||
|
||||
def test_year(self):
|
||||
self.assertEqual(num2words(2002, to='year', lang='de'),
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# encoding: UTF-8
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
@@ -13,6 +14,7 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# encoding: UTF-8
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# encoding: UTF-8
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
@@ -13,7 +14,6 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from num2words import num2words
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copetright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This libraret is free software; etou can redistribute it and/or
|
||||
# modifet it under the terms of the GNU Lesser General Public
|
||||
# License as published bet the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at etour option) anet later version.
|
||||
# This libraret is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warrantet of
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copet of the GNU Lesser General Public
|
||||
# License along with this libraret; if not, write to the Free Software
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
@@ -107,10 +107,13 @@ TEST_CASES_ORDINAL = (
|
||||
TEST_CASES_ORDINAL_NUM = (
|
||||
(1, '1er'),
|
||||
(8, '8me'),
|
||||
(11, '11me'),
|
||||
(12, '12me'),
|
||||
(14, '14me'),
|
||||
(21, '21me'),
|
||||
(28, '28me'),
|
||||
(100, '100me'),
|
||||
(101, '101me'),
|
||||
(1000, '1000me'),
|
||||
(1000000, '1000000me')
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@@ -13,7 +14,6 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
93
tests/test_ko.py
Normal file
93
tests/test_ko.py
Normal file
@@ -0,0 +1,93 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words import num2words
|
||||
|
||||
|
||||
def n2k(*args, **kwargs):
|
||||
return num2words(*args, lang='ko', **kwargs)
|
||||
|
||||
|
||||
class Num2WordsKOTest(TestCase):
|
||||
def test_low(self):
|
||||
cases = [(0, "영"), (1, "일"), (2, "이"), (3, "삼"), (4, "사"), (5, "오"),
|
||||
(6, "육"), (7, "칠"), (8, "팔"), (9, "구"), (10, "십"),
|
||||
(11, "십일"), (12, "십이"), (13, "십삼"), (14, "십사"),
|
||||
(15, "십오"), (16, "십육"), (17, "십칠"),
|
||||
(18, "십팔"), (19, "십구"), (20, "이십"), (25, "이십오"),
|
||||
(31, "삼십일"), (42, "사십이"), (54, "오십사"), (63, "육십삼"),
|
||||
(76, "칠십육"), (89, "팔십구"), (98, "구십팔")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num), out)
|
||||
|
||||
def test_mid(self):
|
||||
cases = [(100, "백"), (121, "백이십일"), (160, "백육십"), (256, "이백오십육"),
|
||||
(285, "이백팔십오"), (486, "사백팔십육"), (627, "육백이십칠"),
|
||||
(808, "팔백팔"), (999, "구백구십구"), (1004, "천사"),
|
||||
(2018, "이천십팔"), (7063, "칠천육십삼")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num), out)
|
||||
|
||||
def test_high(self):
|
||||
cases = [(10000, "만"), (11020, "만 천이십"), (25891, "이만 오천팔백구십일"),
|
||||
(64237, "육만 사천이백삼십칠"), (241572, "이십사만 천오백칠십이"),
|
||||
(100000000, "일억"), (5000500000000, "오조 오억")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num), out)
|
||||
|
||||
def test_negative(self):
|
||||
cases = [(-11, "마이너스 십일"), (-15, "마이너스 십오"),
|
||||
(-18, "마이너스 십팔"), (-241572, "마이너스 이십사만 천오백칠십이")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num), out)
|
||||
|
||||
def test_year(self):
|
||||
cases = [(2000, "이천년"), (2002, "이천이년"), (2018, "이천십팔년"),
|
||||
(1954, "천구백오십사년"), (1910, "천구백십년"), (-1000, "기원전 천년")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num, to="year"), out)
|
||||
|
||||
def test_currency(self):
|
||||
cases_krw = [(8350, "팔천삼백오십원"), (14980, "만사천구백팔십원"),
|
||||
(250004000, "이억오천만사천원")]
|
||||
cases_usd = [(4, "사달러 영센트"), (19.55, "십구달러 오십오센트")]
|
||||
cases_jpy = [(15, "십오엔"), (50, "오십엔")]
|
||||
for num, out in cases_krw:
|
||||
self.assertEqual(n2k(num, to="currency"), out)
|
||||
for num, out in cases_usd:
|
||||
self.assertEqual(n2k(num, to="currency", currency="USD"), out)
|
||||
for num, out in cases_jpy:
|
||||
self.assertEqual(n2k(num, to="currency", currency="JPY"), out)
|
||||
with self.assertRaises(ValueError):
|
||||
n2k(190.55, to="currency")
|
||||
with self.assertRaises(NotImplementedError):
|
||||
n2k(4, to="currency", currency="EUR")
|
||||
|
||||
def test_ordinal(self):
|
||||
cases = [(1, "첫 번째"), (101, "백 한 번째"), (2, "두 번째"), (5, "다섯 번째"),
|
||||
(10, "열 번째"), (25, "스물다섯 번째"), (137, "백 서른일곱 번째")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num, to="ordinal"), out)
|
||||
|
||||
def test_ordinal_num(self):
|
||||
cases = [(1, "1 번째"), (101, "101 번째"), (25, "25 번째")]
|
||||
for num, out in cases:
|
||||
self.assertEqual(n2k(num, to="ordinal_num"), out)
|
||||
@@ -1,4 +1,20 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
@@ -53,9 +69,6 @@ class Num2WordsLTTest(TestCase):
|
||||
'minus penki tūkstančiai kablelis dvidešimt du',
|
||||
)
|
||||
|
||||
# print(fill(n2w(1000000000000000000000000000000)))
|
||||
# naintilijonas
|
||||
|
||||
def test_to_ordinal(self):
|
||||
# @TODO: implement to_ordinal
|
||||
with self.assertRaises(NotImplementedError):
|
||||
|
||||
@@ -1,4 +1,20 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
@@ -48,9 +64,6 @@ class Num2WordsLVTest(TestCase):
|
||||
'mīnus pieci tūkstoši komats divdesmit divi',
|
||||
)
|
||||
|
||||
# >>> print(fill(n2w(1000000000000000000000000000000)))
|
||||
# nontiljons
|
||||
|
||||
self.assertEqual(num2words(0, lang='lv'), 'nulle')
|
||||
self.assertEqual(num2words(5, lang='lv'), "pieci")
|
||||
self.assertEqual(num2words(15, lang='lv'), "piecpadsmit")
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
@@ -45,6 +46,10 @@ class Num2WordsPLTest(TestCase):
|
||||
"miliard dwieście trzydzieści cztery miliony pięćset "
|
||||
"sześćdziesiąt siedem tysięcy osiemset dziewięćdzisiąt"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(10000000001000000100000, lang='pl'),
|
||||
"dziesięć tryliardów bilion sto tysięcy"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(215461407892039002157189883901676, lang='pl'),
|
||||
"dwieście piętnaście kwintylionów czterysta sześćdziesiąt jeden "
|
||||
@@ -52,7 +57,7 @@ class Num2WordsPLTest(TestCase):
|
||||
"dziewięćdzisiąt dwa tryliardy trzydzieści dziewięć trylionów "
|
||||
"dwa biliardy sto pięćdziesiąt siedem bilionów sto osiemdziesiąt "
|
||||
"dziewięć miliardów osiemset osiemdziesiąt trzy miliony "
|
||||
"dziewęćset jeden tysięcy sześćset siedemdziesiąt sześć"
|
||||
"dziewięćset jeden tysięcy sześćset siedemdziesiąt sześć"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(719094234693663034822824384220291, lang='pl'),
|
||||
@@ -64,6 +69,18 @@ class Num2WordsPLTest(TestCase):
|
||||
"osiemdziesiąt cztery miliony dwieście dwadzieścia "
|
||||
"tysięcy dwieście dziewięćdzisiąt jeden"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(
|
||||
963301000001918264129471001047146102 * 10**30 + 1007,
|
||||
lang='pl'
|
||||
),
|
||||
"dziewięćset sześćdziesiąt trzy decyliardy trzysta jeden "
|
||||
"decylionów nonylion dziewięćset osiemnaście oktyliardów dwieście "
|
||||
"sześćdziesiąt cztery oktyliony sto dwadzieścia dziewięć "
|
||||
"septyliardów czterysta siedemdziesiąt jeden septylionów "
|
||||
"sekstyliard czterdzieści siedem sekstylionów sto czterdzieści "
|
||||
"sześć kwintyliardów sto dwa kwintyliony tysiąc siedem"
|
||||
)
|
||||
|
||||
def test_to_ordinal(self):
|
||||
# @TODO: implement to_ordinal
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
@@ -13,6 +14,7 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
243
tests/test_sr.py
Normal file
243
tests/test_sr.py
Normal file
@@ -0,0 +1,243 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words import num2words
|
||||
|
||||
|
||||
class Num2WordsSRTest(TestCase):
|
||||
|
||||
def test_cardinal(self):
|
||||
self.assertEqual("sto", num2words(100, lang='sr'))
|
||||
self.assertEqual("sto jedan", num2words(101, lang='sr'))
|
||||
self.assertEqual("sto deset", num2words(110, lang='sr'))
|
||||
self.assertEqual("sto petnaest", num2words(115, lang='sr'))
|
||||
self.assertEqual(
|
||||
"sto dvadeset tri", num2words(123, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"jedna hiljada", num2words(1000, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"jedna hiljada jedan", num2words(1001, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"dve hiljade dvanaest", num2words(2012, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"dvanaest hiljada petsto devetnaest zapeta osamdeset pet",
|
||||
num2words(12519.85, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"jedan bilion dvesta trideset četiri miliona petsto "
|
||||
"šezdeset sedam hiljada osamsto devedeset",
|
||||
num2words(1234567890, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"dvesta petnaest noniliona četristo šezdeset jedan "
|
||||
"oktilion četristo sedam septiliona osamsto devedeset "
|
||||
"dva sekstiliona trideset devet kvintiliona dva kvadriliona "
|
||||
"sto pedeset sedam triliona sto osamdeset devet biliona "
|
||||
"osamsto osamdeset tri miliona devetsto jedna hiljada "
|
||||
"šesto sedamdeset šest",
|
||||
num2words(215461407892039002157189883901676, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"sedamsto devetnaest noniliona devedeset četiri oktiliona "
|
||||
"dvesta trideset četiri septiliona šesto devedeset tri "
|
||||
"sekstiliona šesto šezdeset tri kvintiliona trideset "
|
||||
"četiri kvadriliona osamsto dvadeset dva triliona osamsto "
|
||||
"dvadeset četiri biliona trista osamdeset četiri miliona "
|
||||
"dvesta dvadeset hiljada dvesta devedeset jedan",
|
||||
num2words(719094234693663034822824384220291, lang='sr')
|
||||
)
|
||||
self.assertEqual("pet", num2words(5, lang='sr'))
|
||||
self.assertEqual("petnaest", num2words(15, lang='sr'))
|
||||
self.assertEqual("sto pedeset četiri", num2words(154, lang='sr'))
|
||||
self.assertEqual(
|
||||
"jedna hiljada sto trideset pet",
|
||||
num2words(1135, lang='sr')
|
||||
)
|
||||
self.assertEqual(
|
||||
"četristo osamnaest hiljada petsto trideset jedan",
|
||||
num2words(418531, lang='sr'),
|
||||
)
|
||||
self.assertEqual(
|
||||
"jedan milion sto trideset devet",
|
||||
num2words(1000139, lang='sr')
|
||||
)
|
||||
|
||||
def test_floating_point(self):
|
||||
self.assertEqual("pet zapeta dva", num2words(5.2, lang='sr'))
|
||||
self.assertEqual(
|
||||
"petsto šezdeset jedan zapeta četrdeset dva",
|
||||
num2words(561.42, lang='sr')
|
||||
)
|
||||
|
||||
def test_to_ordinal(self):
|
||||
# @TODO: implement to_ordinal
|
||||
with self.assertRaises(NotImplementedError):
|
||||
num2words(1, lang='sr', to='ordinal')
|
||||
|
||||
def test_to_currency(self):
|
||||
self.assertEqual(
|
||||
'jedan evro, nula centi',
|
||||
num2words(1.0, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dva evra, nula centi',
|
||||
num2words(2.0, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'pet evra, nula centi',
|
||||
num2words(5.0, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dva evra, jedan cent',
|
||||
num2words(2.01, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
'dva evra, dva centa',
|
||||
num2words(2.02, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dva evra, pet centi',
|
||||
num2words(2.05, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dve rublje, nula kopejki',
|
||||
num2words(2.0, lang='sr', to='currency', currency='RUB')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dve rublje, jedna kopejka',
|
||||
num2words(2.01, lang='sr', to='currency', currency='RUB')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dve rublje, dve kopejke',
|
||||
num2words(2.02, lang='sr', to='currency', currency='RUB')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dve rublje, pet kopejki',
|
||||
num2words(2.05, lang='sr', to='currency', currency='RUB')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'jedan dinar, nula para',
|
||||
num2words(1.0, lang='sr', to='currency', currency='RSD')
|
||||
)
|
||||
self.assertEqual(
|
||||
'dva dinara, dve pare',
|
||||
num2words(2.02, lang='sr', to='currency', currency='RSD')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'pet dinara, pet para',
|
||||
num2words(5.05, lang='sr', to='currency', currency='RSD')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'jedanaest dinara, jedanaest para',
|
||||
num2words(11.11, lang='sr', to='currency', currency='RSD')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dvadeset jedan dinar, dvadeset jedna para',
|
||||
num2words(21.21, lang='sr', to='currency', currency='RSD')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dvadeset jedan evro, dvadeset jedan cent',
|
||||
num2words(21.21, lang='sr', to='currency', currency='EUR')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'dvadeset jedna rublja, dvadeset jedna kopejka',
|
||||
num2words(21.21, lang='sr', to='currency', currency='RUB')
|
||||
|
||||
)
|
||||
self.assertEqual(
|
||||
'jedna hiljada dvesta trideset četiri evra, '
|
||||
'pedeset šest centi',
|
||||
num2words(
|
||||
1234.56, lang='sr', to='currency', currency='EUR'
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
'jedna hiljada dvesta trideset četiri rublje, '
|
||||
'pedeset šest kopejki',
|
||||
num2words(
|
||||
1234.56, lang='sr', to='currency', currency='RUB'
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
'sto jedan evro i jedanaest centi',
|
||||
num2words(
|
||||
10111,
|
||||
lang='sr',
|
||||
to='currency',
|
||||
currency='EUR',
|
||||
seperator=' i'
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
'sto jedna rublja i dvadeset jedna kopejka',
|
||||
num2words(
|
||||
10121,
|
||||
lang='sr',
|
||||
to='currency',
|
||||
currency='RUB',
|
||||
seperator=' i'
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
'sto jedna rublja i dvadeset dve kopejke',
|
||||
num2words(10122, lang='sr', to='currency', currency='RUB',
|
||||
seperator=' i')
|
||||
)
|
||||
self.assertEqual(
|
||||
'sto jedan evro i dvadeset jedan cent',
|
||||
num2words(10121, lang='sr', to='currency', currency='EUR',
|
||||
seperator=' i'),
|
||||
)
|
||||
self.assertEqual(
|
||||
'minus dvanaest hiljada petsto devetnaest evra, 85 centi',
|
||||
num2words(
|
||||
-1251985,
|
||||
lang='sr',
|
||||
to='currency',
|
||||
currency='EUR',
|
||||
cents=False
|
||||
)
|
||||
)
|
||||
self.assertEqual(
|
||||
"trideset osam evra i 40 centi",
|
||||
num2words('38.4', lang='sr', to='currency', seperator=' i',
|
||||
cents=False, currency='EUR'),
|
||||
)
|
||||
401
tests/test_th.py
401
tests/test_th.py
@@ -1,193 +1,208 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words import num2words
|
||||
from num2words.lang_TH import Num2Word_TH
|
||||
|
||||
|
||||
class TestNumWord(TestCase):
|
||||
|
||||
def test_0(self):
|
||||
self.assertEqual(num2words(0, lang='th'), "ศูนย์")
|
||||
|
||||
def test_end_with_1(self):
|
||||
self.assertEqual(num2words(21, lang='th'), "ยี่สิบเอ็ด")
|
||||
self.assertEqual(num2words(11, lang='th'), "สิบเอ็ด")
|
||||
self.assertEqual(num2words(101, lang='th'), "หนึ่งร้อยเอ็ด")
|
||||
self.assertEqual(num2words(1201, lang='th'), "หนึ่งพันสองร้อยเอ็ด")
|
||||
|
||||
def test_start_20(self):
|
||||
self.assertEqual(num2words(22, lang='th'), "ยี่สิบสอง")
|
||||
self.assertEqual(num2words(27, lang='th'), "ยี่สิบเจ็ด")
|
||||
|
||||
def test_start_10(self):
|
||||
self.assertEqual(num2words(10, lang='th'), "สิบ")
|
||||
self.assertEqual(num2words(18, lang='th'), "สิบแปด")
|
||||
|
||||
def test_1_to_9(self):
|
||||
self.assertEqual(num2words(1, lang='th'), "หนึ่ง")
|
||||
self.assertEqual(num2words(5, lang='th'), "ห้า")
|
||||
self.assertEqual(num2words(9, lang='th'), "เก้า")
|
||||
|
||||
def test_31_to_99(self):
|
||||
self.assertEqual(num2words(31, lang='th'), "สามสิบเอ็ด")
|
||||
self.assertEqual(num2words(48, lang='th'), "สี่สิบแปด")
|
||||
self.assertEqual(num2words(76, lang='th'), "เจ็ดสิบหก")
|
||||
|
||||
def test_100_to_999(self):
|
||||
self.assertEqual(num2words(100, lang='th'), "หนึ่งร้อย")
|
||||
self.assertEqual(num2words(123, lang='th'), "หนึ่งร้อยยี่สิบสาม")
|
||||
self.assertEqual(num2words(456, lang='th'), "สี่ร้อยห้าสิบหก")
|
||||
self.assertEqual(num2words(721, lang='th'), "เจ็ดร้อยยี่สิบเอ็ด")
|
||||
|
||||
def test_1000_to_9999(self):
|
||||
self.assertEqual(num2words(1000, lang='th'), "หนึ่งพัน")
|
||||
self.assertEqual(
|
||||
num2words(2175, lang='th'), "สองพันหนึ่งร้อยเจ็ดสิบห้า"
|
||||
)
|
||||
self.assertEqual(num2words(4582, lang='th'), "สี่พันห้าร้อยแปดสิบสอง")
|
||||
self.assertEqual(num2words(9346, lang='th'), "เก้าพันสามร้อยสี่สิบหก")
|
||||
|
||||
def test_10000_to_99999(self):
|
||||
self.assertEqual(
|
||||
num2words(11111, lang='th'), "หนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(22222, lang='th'), "สองหมื่นสองพันสองร้อยยี่สิบสอง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(84573, lang='th'), "แปดหมื่นสี่พันห้าร้อยเจ็ดสิบสาม"
|
||||
)
|
||||
|
||||
def test_100000_to_999999(self):
|
||||
self.assertEqual(
|
||||
num2words(153247, lang='th'),
|
||||
"หนึ่งแสนห้าหมื่นสามพันสองร้อยสี่สิบเจ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(562442, lang='th'),
|
||||
"ห้าแสนหกหมื่นสองพันสี่ร้อยสี่สิบสอง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(999999, lang='th'),
|
||||
"เก้าแสนเก้าหมื่นเก้าพันเก้าร้อยเก้าสิบเก้า"
|
||||
)
|
||||
|
||||
def test_more_than_million(self):
|
||||
self.assertEqual(
|
||||
num2words(1000000, lang='th'),
|
||||
"หนึ่งล้าน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000001, lang='th'),
|
||||
"หนึ่งล้านเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(42478941, lang='th'),
|
||||
"สี่สิบสองล้านสี่แสนเจ็ดหมื่นแปดพันเก้าร้อยสี่สิบเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(712696969, lang='th'),
|
||||
"เจ็ดร้อยสิบสองล้านหกแสนเก้าหมื่นหกพันเก้าร้อยหกสิบเก้า"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000000000000000001, lang='th'),
|
||||
"หนึ่งล้านล้านล้านเอ็ด"
|
||||
)
|
||||
|
||||
def test_decimal(self):
|
||||
self.assertEqual(
|
||||
num2words(0.0, lang='th'), "ศูนย์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.0038, lang='th'), "ศูนย์จุดศูนย์ศูนย์สามแปด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.01, lang='th'), "ศูนย์จุดศูนย์หนึ่ง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1.123, lang='th'), "หนึ่งจุดหนึ่งสองสาม"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(35.37, lang='th'), "สามสิบห้าจุดสามเจ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000000.01, lang='th'), "หนึ่งล้านจุดศูนย์หนึ่ง"
|
||||
)
|
||||
|
||||
def test_currency(self):
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='THB'),
|
||||
"หนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='USD'),
|
||||
"หนึ่งร้อยดอลลาร์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='EUR'),
|
||||
"หนึ่งร้อยยูโร"
|
||||
)
|
||||
|
||||
def test_currency_decimal(self):
|
||||
self.assertEqual(
|
||||
num2words(0.00, lang='th', to='currency'), "ศูนย์บาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.05, lang='th', to='currency'), "ห้าสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.50, lang='th', to='currency'), "ห้าสิบสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.99, lang='th', to='currency'), "เก้าสิบเก้าสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.00, lang='th', to='currency'), "หนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.23, lang='th', to='currency', currency='USD'),
|
||||
"หนึ่งร้อยดอลลาร์ยี่สิบสามเซนต์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.24, lang='th', to='currency', currency='EUR'),
|
||||
"หนึ่งร้อยยูโรยี่สิบสี่เซนต์"
|
||||
)
|
||||
|
||||
def test_negative(self):
|
||||
self.assertEqual(num2words(-10, lang='th'), "ติดลบสิบ")
|
||||
self.assertEqual(num2words(-10.50, lang='th'), "ติดลบสิบจุดห้า")
|
||||
self.assertEqual(
|
||||
num2words(-100.00, lang='th', to='currency'),
|
||||
"ติดลบหนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
|
||||
def test_round_2_decimal(self):
|
||||
n2wTH = Num2Word_TH()
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.004), ('0.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.005), ('0.01', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.006), ('0.01', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.0005),
|
||||
('0.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.984), ('0.98', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.989), ('0.99', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.994), ('0.99', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.999), ('1.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(-0.994), ('0.99', True))
|
||||
self.assertEqual(n2wTH.round_2_decimal(-0.999), ('1.00', True))
|
||||
# self.assertEqual(n2wTH.round_2_decimal(0.985), ('0.99', False))
|
||||
# Expect 0.99 get 0.98
|
||||
# self.assertEqual(n2wTH.round_2_decimal(0.995), ('1.00', False))
|
||||
# Expect 1.00 get 0.99
|
||||
|
||||
def test_split_six(self):
|
||||
n2wTH = Num2Word_TH()
|
||||
self.assertEqual(n2wTH.split_six(str(123456789)),
|
||||
['987654', '321'])
|
||||
self.assertEqual(n2wTH.split_six(str(12345)),
|
||||
['54321'])
|
||||
self.assertEqual(n2wTH.split_six(str(1234567)),
|
||||
['765432', '1'])
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words import num2words
|
||||
from num2words.lang_TH import Num2Word_TH
|
||||
|
||||
|
||||
class TestNumWord(TestCase):
|
||||
|
||||
def test_0(self):
|
||||
self.assertEqual(num2words(0, lang='th'), "ศูนย์")
|
||||
|
||||
def test_end_with_1(self):
|
||||
self.assertEqual(num2words(21, lang='th'), "ยี่สิบเอ็ด")
|
||||
self.assertEqual(num2words(11, lang='th'), "สิบเอ็ด")
|
||||
self.assertEqual(num2words(101, lang='th'), "หนึ่งร้อยเอ็ด")
|
||||
self.assertEqual(num2words(1201, lang='th'), "หนึ่งพันสองร้อยเอ็ด")
|
||||
|
||||
def test_start_20(self):
|
||||
self.assertEqual(num2words(22, lang='th'), "ยี่สิบสอง")
|
||||
self.assertEqual(num2words(27, lang='th'), "ยี่สิบเจ็ด")
|
||||
|
||||
def test_start_10(self):
|
||||
self.assertEqual(num2words(10, lang='th'), "สิบ")
|
||||
self.assertEqual(num2words(18, lang='th'), "สิบแปด")
|
||||
|
||||
def test_1_to_9(self):
|
||||
self.assertEqual(num2words(1, lang='th'), "หนึ่ง")
|
||||
self.assertEqual(num2words(5, lang='th'), "ห้า")
|
||||
self.assertEqual(num2words(9, lang='th'), "เก้า")
|
||||
|
||||
def test_31_to_99(self):
|
||||
self.assertEqual(num2words(31, lang='th'), "สามสิบเอ็ด")
|
||||
self.assertEqual(num2words(48, lang='th'), "สี่สิบแปด")
|
||||
self.assertEqual(num2words(76, lang='th'), "เจ็ดสิบหก")
|
||||
|
||||
def test_100_to_999(self):
|
||||
self.assertEqual(num2words(100, lang='th'), "หนึ่งร้อย")
|
||||
self.assertEqual(num2words(123, lang='th'), "หนึ่งร้อยยี่สิบสาม")
|
||||
self.assertEqual(num2words(456, lang='th'), "สี่ร้อยห้าสิบหก")
|
||||
self.assertEqual(num2words(721, lang='th'), "เจ็ดร้อยยี่สิบเอ็ด")
|
||||
|
||||
def test_1000_to_9999(self):
|
||||
self.assertEqual(num2words(1000, lang='th'), "หนึ่งพัน")
|
||||
self.assertEqual(
|
||||
num2words(2175, lang='th'), "สองพันหนึ่งร้อยเจ็ดสิบห้า"
|
||||
)
|
||||
self.assertEqual(num2words(4582, lang='th'), "สี่พันห้าร้อยแปดสิบสอง")
|
||||
self.assertEqual(num2words(9346, lang='th'), "เก้าพันสามร้อยสี่สิบหก")
|
||||
|
||||
def test_10000_to_99999(self):
|
||||
self.assertEqual(
|
||||
num2words(11111, lang='th'), "หนึ่งหมื่นหนึ่งพันหนึ่งร้อยสิบเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(22222, lang='th'), "สองหมื่นสองพันสองร้อยยี่สิบสอง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(84573, lang='th'), "แปดหมื่นสี่พันห้าร้อยเจ็ดสิบสาม"
|
||||
)
|
||||
|
||||
def test_100000_to_999999(self):
|
||||
self.assertEqual(
|
||||
num2words(153247, lang='th'),
|
||||
"หนึ่งแสนห้าหมื่นสามพันสองร้อยสี่สิบเจ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(562442, lang='th'),
|
||||
"ห้าแสนหกหมื่นสองพันสี่ร้อยสี่สิบสอง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(999999, lang='th'),
|
||||
"เก้าแสนเก้าหมื่นเก้าพันเก้าร้อยเก้าสิบเก้า"
|
||||
)
|
||||
|
||||
def test_more_than_million(self):
|
||||
self.assertEqual(
|
||||
num2words(1000000, lang='th'),
|
||||
"หนึ่งล้าน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000001, lang='th'),
|
||||
"หนึ่งล้านเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(42478941, lang='th'),
|
||||
"สี่สิบสองล้านสี่แสนเจ็ดหมื่นแปดพันเก้าร้อยสี่สิบเอ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(712696969, lang='th'),
|
||||
"เจ็ดร้อยสิบสองล้านหกแสนเก้าหมื่นหกพันเก้าร้อยหกสิบเก้า"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000000000000000001, lang='th'),
|
||||
"หนึ่งล้านล้านล้านเอ็ด"
|
||||
)
|
||||
|
||||
def test_decimal(self):
|
||||
self.assertEqual(
|
||||
num2words(0.0, lang='th'), "ศูนย์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.0038, lang='th'), "ศูนย์จุดศูนย์ศูนย์สามแปด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.01, lang='th'), "ศูนย์จุดศูนย์หนึ่ง"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1.123, lang='th'), "หนึ่งจุดหนึ่งสองสาม"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(35.37, lang='th'), "สามสิบห้าจุดสามเจ็ด"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(1000000.01, lang='th'), "หนึ่งล้านจุดศูนย์หนึ่ง"
|
||||
)
|
||||
|
||||
def test_currency(self):
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='THB'),
|
||||
"หนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='USD'),
|
||||
"หนึ่งร้อยดอลลาร์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100, lang='th', to='currency', currency='EUR'),
|
||||
"หนึ่งร้อยยูโร"
|
||||
)
|
||||
|
||||
def test_currency_decimal(self):
|
||||
self.assertEqual(
|
||||
num2words(0.00, lang='th', to='currency'), "ศูนย์บาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.05, lang='th', to='currency'), "ห้าสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.50, lang='th', to='currency'), "ห้าสิบสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(0.99, lang='th', to='currency'), "เก้าสิบเก้าสตางค์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.00, lang='th', to='currency'), "หนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.23, lang='th', to='currency', currency='USD'),
|
||||
"หนึ่งร้อยดอลลาร์ยี่สิบสามเซนต์"
|
||||
)
|
||||
self.assertEqual(
|
||||
num2words(100.24, lang='th', to='currency', currency='EUR'),
|
||||
"หนึ่งร้อยยูโรยี่สิบสี่เซนต์"
|
||||
)
|
||||
|
||||
def test_negative(self):
|
||||
self.assertEqual(num2words(-10, lang='th'), "ติดลบสิบ")
|
||||
self.assertEqual(num2words(-10.50, lang='th'), "ติดลบสิบจุดห้า")
|
||||
self.assertEqual(
|
||||
num2words(-100.00, lang='th', to='currency'),
|
||||
"ติดลบหนึ่งร้อยบาทถ้วน"
|
||||
)
|
||||
|
||||
def test_round_2_decimal(self):
|
||||
n2wTH = Num2Word_TH()
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.004), ('0.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.005), ('0.01', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.006), ('0.01', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.0005),
|
||||
('0.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.984), ('0.98', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.989), ('0.99', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.994), ('0.99', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(0.999), ('1.00', False))
|
||||
self.assertEqual(n2wTH.round_2_decimal(-0.994), ('0.99', True))
|
||||
self.assertEqual(n2wTH.round_2_decimal(-0.999), ('1.00', True))
|
||||
# self.assertEqual(n2wTH.round_2_decimal(0.985), ('0.99', False))
|
||||
# Expect 0.99 get 0.98
|
||||
# self.assertEqual(n2wTH.round_2_decimal(0.995), ('1.00', False))
|
||||
# Expect 1.00 get 0.99
|
||||
|
||||
def test_split_six(self):
|
||||
n2wTH = Num2Word_TH()
|
||||
self.assertEqual(n2wTH.split_six(str(123456789)),
|
||||
['987654', '321'])
|
||||
self.assertEqual(n2wTH.split_six(str(12345)),
|
||||
['54321'])
|
||||
self.assertEqual(n2wTH.split_six(str(1234567)),
|
||||
['765432', '1'])
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# Copyright (c) 2017, Tufan Kaynak, Framras. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
@@ -13,6 +14,7 @@
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
@@ -1,24 +1,41 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words.utils import splitbyx
|
||||
|
||||
|
||||
class TestUtils(TestCase):
|
||||
def test_splitbyx(self):
|
||||
self.assertEqual(list(splitbyx(str(12), 3)), [12])
|
||||
self.assertEqual(list(splitbyx(str(1234), 3)), [1, 234])
|
||||
self.assertEqual(list(splitbyx(str(12345678900), 3)),
|
||||
[12, 345, 678, 900]
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(1000000), 6)), [1, 0])
|
||||
|
||||
self.assertEqual(list(splitbyx(str(12), 3, format_int=False)), ['12'])
|
||||
self.assertEqual(list(splitbyx(str(1234), 3, format_int=False)),
|
||||
['1', '234']
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(12345678900), 3, format_int=False)),
|
||||
['12', '345', '678', '900']
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(1000000), 6, format_int=False)),
|
||||
['1', '000000']
|
||||
)
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2.1 of the License, or (at your option) any later version.
|
||||
# This library is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# Lesser General Public License for more details.
|
||||
# You should have received a copy of the GNU Lesser General Public
|
||||
# License along with this library; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
# MA 02110-1301 USA
|
||||
|
||||
from unittest import TestCase
|
||||
|
||||
from num2words.utils import splitbyx
|
||||
|
||||
|
||||
class TestUtils(TestCase):
|
||||
def test_splitbyx(self):
|
||||
self.assertEqual(list(splitbyx(str(12), 3)), [12])
|
||||
self.assertEqual(list(splitbyx(str(1234), 3)), [1, 234])
|
||||
self.assertEqual(list(splitbyx(str(12345678900), 3)),
|
||||
[12, 345, 678, 900]
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(1000000), 6)), [1, 0])
|
||||
|
||||
self.assertEqual(list(splitbyx(str(12), 3, format_int=False)), ['12'])
|
||||
self.assertEqual(list(splitbyx(str(1234), 3, format_int=False)),
|
||||
['1', '234']
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(12345678900), 3, format_int=False)),
|
||||
['12', '345', '678', '900']
|
||||
)
|
||||
self.assertEqual(list(splitbyx(str(1000000), 6, format_int=False)),
|
||||
['1', '000000']
|
||||
)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015, Savoir-faire Linux inc. All Rights Reserved.
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright (c) 2003, Taro Ogawa. All Rights Reserved.
|
||||
# Copyright (c) 2013, Savoir-faire Linux inc. All Rights Reserved.
|
||||
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
|
||||
Reference in New Issue
Block a user