Skip to content

Commit

Permalink
Add test to improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlon Rodriguez Garcia committed Nov 19, 2024
1 parent 8c712e9 commit a960b9f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 2 additions & 3 deletions num2words/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ def __init__(self):
self.errmsg_floatord = "Cannot treat float %s as ordinal."
self.errmsg_negord = "Cannot treat negative num %s as ordinal."
self.errmsg_toobig = "abs(%s) must be less than %s."

self.cards = OrderedDict()
self.setup()

# uses cards
if any(hasattr(self, field) for field in
['high_numwords', 'mid_numwords', 'low_numwords']):
self.cards = OrderedDict()
self.set_numwords()
self.MAXVAL = 1000 * list(self.cards.keys())[0]

Expand Down Expand Up @@ -111,7 +110,7 @@ def to_cardinal(self, value):
value = abs(value)
out = "%s " % self.negword.strip()

if value >= self.MAXVAL:
if hasattr(self, 'MAXVAL') and value >= self.MAXVAL:
raise OverflowError(self.errmsg_toobig % (value, self.MAXVAL))

val = self.splitnum(value)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ def test_is_title(self):
self.base.title("one"),
"one"
)

def test_set_high_numwords_not_implemented(self):
with self.assertRaises(NotImplementedError):
self.base.set_high_numwords()

def test_to_ordinal(self):
from num2words.base import Num2Word_Base
self.base = Num2Word_Base()
self.assertEqual(self.base.to_ordinal(1), "1st")
self.assertEqual(self.base.to_ordinal(11), "11th")
self.assertEqual(self.base.to_ordinal(21), "21st")
self.assertEqual(self.base.to_ordinal(100), "100th")
self.assertEqual(self.base.to_ordinal(123), "123rd")

0 comments on commit a960b9f

Please sign in to comment.