Browse Source

added test for extraction of a positive constant without math operators as well as corresponding functionality

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

5
src/main/py/read_math_function.py

@ -52,3 +52,8 @@ def simplify_easy_math_function(type, function):
return False
if is_string(function) == False or is_allowed_string("c", function) == True:
return simplify_constant("c", function)
def extract_constant(function):
coefficient, constant = function.split('x', 1) if 'x' in function else (function, '')
constant = constant.lstrip('+')
return [constant, f"{coefficient}x"]

2
src/test/py/test_read_math_function.py

@ -38,6 +38,8 @@ class read_function(unittest.TestCase):
self.assertEqual(simplify_easy_math_function("v", 42), 42)
def test_easy_function_string_is_constant(self):
self.assertEqual(simplify_easy_math_function("v", "42^(2)+1-3*4/3"), 1761)
def test_extraction_linear_function_constant_without_math_operators_addition(self):
self.assertEqual(extract_constant("42x+5"), ["5", "42x"])
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save