Skip to content

Commit

Permalink
check for non-integerness before range
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Pilgrim committed Sep 17, 2010
1 parent dc45dd3 commit 76a14e4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions examples/roman10.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ class InvalidRomanNumeralError(ValueError): pass

def to_roman(n):
'''convert integer to Roman numeral'''
if not (0 < n < 5000):
raise OutOfRangeError('number out of range (must be 1..4999)')
if int(n) != n:
raise NotIntegerError('non-integers can not be converted')
if not (0 < n < 5000):
raise OutOfRangeError('number out of range (must be 1..4999)')
return to_roman_table[n]

def from_roman(s):
Expand Down
4 changes: 2 additions & 2 deletions examples/roman9.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class InvalidRomanNumeralError(ValueError): pass

def to_roman(n):
'''convert integer to Roman numeral'''
if not (0 < n < 5000):
raise OutOfRangeError('number out of range (must be 1..4999)')
if not isinstance(n, int):
raise NotIntegerError('non-integers can not be converted')
if not (0 < n < 5000):
raise OutOfRangeError('number out of range (must be 1..4999)')

result = ''
for numeral, integer in roman_numeral_map:
Expand Down
4 changes: 2 additions & 2 deletions refactoring.html
Original file line number Diff line number Diff line change
Expand Up @@ -240,10 +240,10 @@ <h2 id=changing-requirements>Handling Changing Requirements</h2>

def to_roman(n):
'''convert integer to Roman numeral'''
<a> if not (0 &lt; n &lt; 5000): <span class=u>&#x2461;</span></a>
raise OutOfRangeError('number out of range (must be 1..4999)')
if not isinstance(n, int):
raise NotIntegerError('non-integers can not be converted')
<a> if not (0 &lt; n &lt; 5000): <span class=u>&#x2461;</span></a>
raise OutOfRangeError('number out of range (must be 1..4999)')

result = ''
for numeral, integer in roman_numeral_map:
Expand Down
2 changes: 1 addition & 1 deletion util/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
try:
import html5lib
except ImportError:
sys.path.insert(0, '/Users/pilgrim/code/html5lib/python3/src/')
sys.path.insert(0, '/home/pilgrim/code/html5lib/python3/src/')
import html5lib

input_filename = sys.argv[1]
Expand Down

0 comments on commit 76a14e4

Please sign in to comment.