Skip to content

Commit 1e7f4e4

Browse files
committed
two more tests to get me to 100% coverage :D
1 parent aab5d90 commit 1e7f4e4

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

shortener/baseconv.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def from_decimal(self, i):
4343
def to_decimal(self, s):
4444
if not isinstance(s, basestring):
4545
raise DecodingError('%s is not a basestring()' % s)
46-
for char in s:
47-
if char not in self.digits:
46+
for index, char in enumerate(s):
47+
if char not in self.digits and not char == '-' and not index == 0:
4848
raise DecodingError('Invalid character for encoding: %s' % char)
4949
return int(self.convert(s, self.digits, self.decimal_digits))
5050

shortener/tests.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,17 @@ def test_create_with_custom_id(self):
204204
link = Link.objects.create(id=id, url='http://www.python.org')
205205
self.assertEqual(link.to_base62(), base62.from_decimal(id))
206206

207+
def test_unicode(self):
208+
"""
209+
unicode test
210+
"""
211+
url = 'http://www.python.org'
212+
link = Link.objects.create(url=url)
213+
self.assertTrue(url in unicode(link))
214+
207215

208216
class BaseconvTestCase(TestCase):
209-
def test_symmetry_int(self):
217+
def test_symmetry_positive_int(self):
210218
"""
211219
symmetry for encoding/decoding values
212220
"""
@@ -215,6 +223,15 @@ def test_symmetry_int(self):
215223
encoded_int = base62.from_decimal(random_int)
216224
self.assertEqual(random_int, base62.to_decimal(encoded_int))
217225

226+
def test_symmetry_negative_int(self):
227+
"""
228+
symmetry for negative numbers
229+
"""
230+
for x in xrange(1000):
231+
random_int = random.randint(-1 * sys.maxint - 1, 0)
232+
encoded_int = base62.from_decimal(random_int)
233+
self.assertEqual(random_int, base62.to_decimal(encoded_int))
234+
218235
def test_encoding_non_int_fails(self):
219236
"""
220237
calling from_decimal() on letters raises an EncodingError

0 commit comments

Comments
 (0)