Do not accept floating numbers
This commit is contained in:
parent
ae6664b7cf
commit
1aaecd4b84
@ -150,6 +150,9 @@ class Expression(object):
|
|||||||
tokens.append("*")
|
tokens.append("*")
|
||||||
tokens.append(character)
|
tokens.append(character)
|
||||||
|
|
||||||
|
elif character == ".":
|
||||||
|
raise ValueError("No float number please")
|
||||||
|
|
||||||
elif character != " ":
|
elif character != " ":
|
||||||
raise ValueError("{} is an unvalid character".format(character))
|
raise ValueError("{} is an unvalid character".format(character))
|
||||||
|
|
||||||
|
@ -48,6 +48,10 @@ class TestExpression(unittest.TestCase):
|
|||||||
tok = Expression.str2tokens(exp)
|
tok = Expression.str2tokens(exp)
|
||||||
self.assertEqual(tok, [-3, "*","(", 2, ")" ])
|
self.assertEqual(tok, [-3, "*","(", 2, ")" ])
|
||||||
|
|
||||||
|
def test_str2tokens_error_float(self):
|
||||||
|
exp = "1 + 1.3"
|
||||||
|
self.assertRaises(ValueError, Expression.str2tokens, exp)
|
||||||
|
|
||||||
def test_str2tokens_error(self):
|
def test_str2tokens_error(self):
|
||||||
exp = "1 + $"
|
exp = "1 + $"
|
||||||
self.assertRaises(ValueError, Expression.str2tokens, exp)
|
self.assertRaises(ValueError, Expression.str2tokens, exp)
|
||||||
|
Loading…
Reference in New Issue
Block a user