Browse Source

added test for decision to calculate string with calculate_string as well as corresponding functionality

remotes/origin/feature/feature-read-math-functions
fdai7763 11 months ago
parent
commit
c372688e95
  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

@ -1,6 +1,10 @@
def read_constant(type, value): def read_constant(type, value):
if type != "c": if type != "c":
return False return False
if is_string(value):
if is_allowed_string(type, value):
constant = calculate_string(value)
return constant
return value return value

2
src/test/py/test_read_math_function.py

@ -19,6 +19,8 @@ class read_function(unittest.TestCase):
self.assertEqual(calculate_string("42+1-3*4/3"), 39) self.assertEqual(calculate_string("42+1-3*4/3"), 39)
def test_constant_calculate_with_pow(self): def test_constant_calculate_with_pow(self):
self.assertEqual(calculate_string("42^(2)+1-3*4/3"), 1761) self.assertEqual(calculate_string("42^(2)+1-3*4/3"), 1761)
def test_constant_calculate_string_decision(self):
self.assertEqual(read_constant("c", "42^(2)+1-3*4/3"), 1761)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
Loading…
Cancel
Save