Browse Source

added test for splitting linear function without added constant as well as corresponding functionality

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

4
src/main/py/read_math_function.py

@ -56,5 +56,7 @@ def simplify_easy_math_function(type, function):
def extract_constant(function):
coefficient, constant = function.split('x', 1) if 'x' in function else (function, '')
constant = constant.lstrip('+')
if constant == "":
constant = constant + "+0"
constant = constant.lstrip("+")
return [constant, f"{coefficient}x"]

2
src/test/py/test_read_math_function.py

@ -42,6 +42,8 @@ class read_function(unittest.TestCase):
self.assertEqual(extract_constant("42x+5"), ["5", "42x"])
def test_extraction_linear_function_constant_without_math_operators_subtraction(self):
self.assertEqual(extract_constant("42x-5"), ["-5", "42x"])
def test_extraction_linear_function_no_constant(self):
self.assertEqual(extract_constant("42x"), ["0", "42x"])
if __name__ == '__main__':
unittest.main()
Loading…
Cancel
Save