Browse Source

added test for is_allowed_string returning true if it has only digits and allowed characters as well as corresponding functionality

remotes/origin/feature/feature-read-math-functions
fdai7763 11 months ago
parent
commit
163a54faa5
  1. 6
      src/main/py/read_math_function.py
  2. 2
      src/test/py/test_read_math_function.py

6
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

2
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()
Loading…
Cancel
Save