mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-20 01:19:26 +01:00
Added nItems.
This commit is contained in:
parent
5857a17f88
commit
4c980aeb3e
@ -309,6 +309,12 @@ def pluralize(i, s):
|
|||||||
else:
|
else:
|
||||||
return s + 's'
|
return s + 's'
|
||||||
|
|
||||||
|
def nItems(n, item, between=None):
|
||||||
|
if between is None:
|
||||||
|
return '%s %s' % (n, pluralize(n, item))
|
||||||
|
else:
|
||||||
|
return '%s %s %s' % (n, between, pluralize(n, item))
|
||||||
|
|
||||||
def be(i):
|
def be(i):
|
||||||
"""Returns the form of the verb 'to be' based on the number i."""
|
"""Returns the form of the verb 'to be' based on the number i."""
|
||||||
if i == 1:
|
if i == 1:
|
||||||
|
@ -170,5 +170,11 @@ class UtilsTest(unittest.TestCase):
|
|||||||
utils.sortBy(str.lower, L)
|
utils.sortBy(str.lower, L)
|
||||||
self.assertEqual(L, ['abc', 'AD', 'z'])
|
self.assertEqual(L, ['abc', 'AD', 'z'])
|
||||||
|
|
||||||
|
def testNItems(self):
|
||||||
|
self.assertEqual(utils.nItems(1, 'tool', 'crazy'), '1 crazy tool')
|
||||||
|
self.assertEqual(utils.nItems(1, 'tool'), '1 tool')
|
||||||
|
self.assertEqual(utils.nItems(2, 'tool', 'crazy'), '2 crazy tools')
|
||||||
|
self.assertEqual(utils.nItems(2, 'tool'), '2 tools')
|
||||||
|
|
||||||
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
# vim:set shiftwidth=4 tabstop=8 expandtab textwidth=78:
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user