From 163a54faa5adcaf8d327ffd1011f9e379a6dc672 Mon Sep 17 00:00:00 2001 From: fdai7763 Date: Tue, 23 Jan 2024 20:27:29 +0100 Subject: [PATCH] added test for is_allowed_string returning true if it has only digits and allowed characters as well as corresponding functionality --- src/main/py/read_math_function.py | 6 ++++++ src/test/py/test_read_math_function.py | 2 ++ 2 files changed, 8 insertions(+) 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()