diff --git a/src/main/py/read_math_function.py b/src/main/py/read_math_function.py index 7a0d803..370b39b 100644 --- a/src/main/py/read_math_function.py +++ b/src/main/py/read_math_function.py @@ -6,3 +6,9 @@ def read_constant(type, value): def is_string(value): return isinstance(value, str) + + +def is_allowed_string(type, value): + allowed = "+-*/()^" + result = all(character.isdigit() or character in allowed for character in value) + return result \ No newline at end of file diff --git a/src/test/py/test_read_math_function.py b/src/test/py/test_read_math_function.py index c30d2ad..f8e8bf2 100644 --- a/src/test/py/test_read_math_function.py +++ b/src/test/py/test_read_math_function.py @@ -11,6 +11,8 @@ class read_function(unittest.TestCase): self.assertEqual(is_string("42*e^x"), True) def test_constant_isstring_false(self): self.assertEqual(is_string(42), False) + def test_constant_isallowed_string_true(self): + self.assertEqual(is_allowed_string("c", "42^(2)+1-3*4"), True) if __name__ == '__main__': unittest.main()