Do not accept floating numbers

This commit is contained in:
Lafrite 2014-02-28 11:34:31 +01:00
parent ae6664b7cf
commit 1aaecd4b84
2 changed files with 7 additions and 0 deletions

View File

@ -150,6 +150,9 @@ class Expression(object):
tokens.append("*")
tokens.append(character)
elif character == ".":
raise ValueError("No float number please")
elif character != " ":
raise ValueError("{} is an unvalid character".format(character))

View File

@ -48,6 +48,10 @@ class TestExpression(unittest.TestCase):
tok = Expression.str2tokens(exp)
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):
exp = "1 + $"
self.assertRaises(ValueError, Expression.str2tokens, exp)