From f67d64196889492801a9a37140ec9036fa484d12 Mon Sep 17 00:00:00 2001 From: Krzysztof Socha Date: Sat, 25 Feb 2017 22:44:27 +0100 Subject: [PATCH 1/6] Fixed issues with wrong text for currency conversion with whole 10s (e.g., 123.50) --- num2words/lang_PL.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/num2words/lang_PL.py b/num2words/lang_PL.py index 24078d8..369e41f 100644 --- a/num2words/lang_PL.py +++ b/num2words/lang_PL.py @@ -55,6 +55,9 @@ dwa tysiące dwanaście >>> print(n2w(12519.85)) dwanaście tysięcy pięćset dziewiętnaście przecinek osiemdziesiąt pięć +>>> print(n2w(123.50)) +sto dwadzieścia trzy przecinek pięć + >>> print(fill(n2w(1234567890))) miliard dwieście trzydzieści cztery miliony pięćset sześćdziesiąt siedem tysięcy osiemset dziewięćdzisiąt @@ -95,6 +98,9 @@ sto jeden złotych i dwadzieścia jeden groszy >>> print(to_currency(-1251985, cents = False)) minus dwanaście tysięcy pięćset dziewiętnaście euro, 85 centów + +>>> print(to_currency(123.50, 'PLN', seperator=' i')) +sto dwadzieścia trzy złote i pięćdziesiąt groszy """ from __future__ import unicode_literals @@ -207,7 +213,7 @@ def int2word(n): if n3 > 0: words.append(HUNDREDS[n3][0]) - + if n2 > 1: words.append(TWENTIES[n2][0]) @@ -245,6 +251,8 @@ def to_currency(n, currency='EUR', cents=True, seperator=','): n = str(n).replace(',', '.') if '.' in n: left, right = n.split('.') + if len(right)==1: + right = right+'0' else: left, right = n, 0 left, right = int(left), int(right) From d586f620c59152d9ab1c1d26ee992362f32d4c09 Mon Sep 17 00:00:00 2001 From: Krzysztof Socha Date: Mon, 27 Feb 2017 17:18:06 +0100 Subject: [PATCH 2/6] Added unit tests for Polish language --- @test_95559_tmp | 2 ++ @test_95599_tmp | 2 ++ tests/test_pl.py | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 @test_95559_tmp create mode 100644 @test_95599_tmp create mode 100644 tests/test_pl.py diff --git a/@test_95559_tmp b/@test_95559_tmp new file mode 100644 index 0000000..88d54c1 --- /dev/null +++ b/@test_95559_tmp @@ -0,0 +1,2 @@ +z = z+1 +z = z*2 diff --git a/@test_95599_tmp b/@test_95599_tmp new file mode 100644 index 0000000..88d54c1 --- /dev/null +++ b/@test_95599_tmp @@ -0,0 +1,2 @@ +z = z+1 +z = z*2 diff --git a/tests/test_pl.py b/tests/test_pl.py new file mode 100644 index 0000000..b70b9a6 --- /dev/null +++ b/tests/test_pl.py @@ -0,0 +1,49 @@ +# -*- encoding: utf-8 -*- +# Copyright (c) 2015, 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_PL import to_currency + +class Num2WordsPLTest(TestCase): + def test_cardinal(self): + self.assertEqual(num2words(100, lang='pl'), "sto") + self.assertEqual(num2words(101, lang='pl'), "sto jeden") + self.assertEqual(num2words(110, lang='pl'), "sto dziesięć") + self.assertEqual(num2words(115, lang='pl'), "sto piętnaście") + self.assertEqual(num2words(123, lang='pl'), "sto dwadzieścia trzy") + self.assertEqual(num2words(1000, lang='pl'), "tysiąc") + self.assertEqual(num2words(1001, lang='pl'), "tysiąc jeden") + self.assertEqual(num2words(2012, lang='pl'), "dwa tysiące dwanaście") + self.assertEqual(num2words(12519.85, lang='pl'), "dwanaście tysięcy pięćset dziewiętnaście przecinek osiemdziesiąt pięć") + self.assertEqual(num2words(123.50, lang='pl'), "sto dwadzieścia trzy przecinek pięć") + self.assertEqual(num2words(1234567890, lang='pl'), "miliard dwieście trzydzieści cztery miliony pięćset sześćdziesiąt siedem tysięcy osiemset dziewięćdzisiąt") + self.assertEqual(num2words(215461407892039002157189883901676, lang='pl'), "dwieście piętnaście kwintylionów czterysta sześćdziesiąt jeden kwadryliardów czterysta siedem kwadrylionów osiemset 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ść") + self.assertEqual(num2words(719094234693663034822824384220291, lang='pl'), "siedemset dziewiętnaście kwintylionów dziewięćdzisiąt cztery kwadryliardy dwieście trzydzieści cztery kwadryliony sześćset dziewięćdzisiąt trzy tryliardy sześćset sześćdziesiąt trzy tryliony trzydzieści cztery biliardy osiemset dwadzieścia dwa biliony osiemset dwadzieścia cztery miliardy trzysta osiemdziesiąt cztery miliony dwieście dwadzieścia tysięcy dwieście dziewięćdzisiąt jeden") + + def test_currency(self): + self.assertEqual(to_currency(1.0, 'EUR'), "jeden euro, zero centów") + self.assertEqual(to_currency(1.0, 'PLN'), "jeden złoty, zero groszy") + self.assertEqual(to_currency(1234.56, 'EUR'), "tysiąc dwieście trzydzieści cztery euro, pięćdziesiąt sześć centów") + self.assertEqual(to_currency(1234.56, 'PLN'), "tysiąc dwieście trzydzieści cztery złote, pięćdziesiąt sześć groszy") + self.assertEqual(to_currency(10111, 'EUR', seperator=' i'), "sto jeden euro i jedenaście centów") + self.assertEqual(to_currency(10121, 'PLN', seperator=' i'), "sto jeden złotych i dwadzieścia jeden groszy") + self.assertEqual(to_currency(-1251985, cents = False), "minus dwanaście tysięcy pięćset dziewiętnaście euro, 85 centów") + self.assertEqual(to_currency(123.50, 'PLN', seperator=' i'), "sto dwadzieścia trzy złote i pięćdziesiąt groszy") + self.assertEqual(to_currency(1950, cents = False), "dziewiętnaście euro, 50 centów") From 94d4e8599246660fe5fde56e501a825db179120a Mon Sep 17 00:00:00 2001 From: Krzysztof Socha Date: Mon, 27 Feb 2017 17:22:31 +0100 Subject: [PATCH 3/6] Cleaned-up some test files --- .DS_Store | Bin 0 -> 6148 bytes @test_95559_tmp | 2 -- @test_95599_tmp | 2 -- 3 files changed, 4 deletions(-) create mode 100644 .DS_Store delete mode 100644 @test_95559_tmp delete mode 100644 @test_95599_tmp diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 27 Feb 2017 17:23:52 +0100 Subject: [PATCH 4/6] Cleaned-up some test files --- .DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 5008ddfcf53c02e82d7eee2e57c38e5672ef89f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Mon, 27 Feb 2017 21:44:43 +0100 Subject: [PATCH 5/6] Fixed integer division operator (/->//) to work also in python3 --- num2words/lang_PL.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/num2words/lang_PL.py b/num2words/lang_PL.py index 369e41f..4ce7380 100644 --- a/num2words/lang_PL.py +++ b/num2words/lang_PL.py @@ -245,7 +245,7 @@ def to_currency(n, currency='EUR', cents=True, seperator=','): minus = False n = abs(n) - left = n / 100 + left = n // 100 right = n % 100 else: n = str(n).replace(',', '.') From 7fdb61351b740111bfe3596b3f4a1aee4f5da925 Mon Sep 17 00:00:00 2001 From: Krzysztof Socha Date: Mon, 27 Feb 2017 21:57:11 +0100 Subject: [PATCH 6/6] Cleaned-up whitespaces around operators --- num2words/lang_PL.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/num2words/lang_PL.py b/num2words/lang_PL.py index 4ce7380..c232f8a 100644 --- a/num2words/lang_PL.py +++ b/num2words/lang_PL.py @@ -184,7 +184,7 @@ def splitby3(n): if start > 0: yield int(n[:start]) for i in range(start, length, 3): - yield int(n[i:i+3]) + yield int(n[i:i + 3]) else: yield int(n) @@ -194,7 +194,7 @@ def get_digits(n): def pluralize(n, forms): - form = 0 if n==1 else 1 if (n % 10 > 1 and n % 10 < 5 and (n % 100 < 10 or n % 100 > 20)) else 2 + form = 0 if n == 1 else 1 if (n % 10 > 1 and n % 10 < 5 and (n % 100 < 10 or n % 100 > 20)) else 2 return forms[form] @@ -209,8 +209,6 @@ def int2word(n): i -= 1 n1, n2, n3 = get_digits(x) - # print str(n3) + str(n2) + str(n1) - if n3 > 0: words.append(HUNDREDS[n3][0]) @@ -237,7 +235,7 @@ def n2w(n): return int2word(int(n)) -def to_currency(n, currency='EUR', cents=True, seperator=','): +def to_currency(n, currency = 'EUR', cents = True, seperator = ','): if type(n) == int: if n < 0: minus = True @@ -251,8 +249,8 @@ def to_currency(n, currency='EUR', cents=True, seperator=','): n = str(n).replace(',', '.') if '.' in n: left, right = n.split('.') - if len(right)==1: - right = right+'0' + if len(right) == 1: + right = right + '0' else: left, right = n, 0 left, right = int(left), int(right)