diff --git a/pymath/expression.py b/pymath/expression.py index 99f0761..1e63c53 100644 --- a/pymath/expression.py +++ b/pymath/expression.py @@ -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)) diff --git a/test/test_expression.py b/test/test_expression.py index 16276ba..d079e77 100644 --- a/test/test_expression.py +++ b/test/test_expression.py @@ -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)