Last active
August 29, 2015 14:17
-
-
Save bencharb/c830c3ee9b1f28e79534 to your computer and use it in GitHub Desktop.
is positive int
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
def is_positive_int(thing): | |
try: | |
assert(unicode(thing).isdigit()) | |
except Exception: | |
return False | |
else: | |
return True | |
def _test_is_positive_int(): | |
try: | |
for val in 12, '12': | |
assert(is_positive_int(val) is True) | |
for val in '5.0', '-5.0', '-5', -5, True, False, lambda: None, NotImplemented: | |
assert(is_positive_int(val) is False) | |
except AssertionError: | |
print 'test failed' | |
import sys | |
exc_class, exc, tb = sys.exc_info() | |
raise exc_class, exc, tb | |
else: | |
print 'test succeeded' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment