|
@ -2,6 +2,7 @@ import unittest |
|
|
from src.main.py.read_math_function import * |
|
|
from src.main.py.read_math_function import * |
|
|
from unittest.mock import patch |
|
|
from unittest.mock import patch |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class read_function(unittest.TestCase): |
|
|
class read_function(unittest.TestCase): |
|
|
def test_constant_without_calculation(self): |
|
|
def test_constant_without_calculation(self): |
|
|
self.assertEqual(simplify_constant("c", 42), 42) |
|
|
self.assertEqual(simplify_constant("c", 42), 42) |
|
@ -33,31 +34,39 @@ class read_function(unittest.TestCase): |
|
|
def test_constant_string_not_allowed_decision(self): |
|
|
def test_constant_string_not_allowed_decision(self): |
|
|
self.assertEqual(simplify_constant("c", "42^(2)+1-3*4/3x"), False) |
|
|
self.assertEqual(simplify_constant("c", "42^(2)+1-3*4/3x"), False) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@patch('builtins.input', side_effect=["x"]) |
|
|
@patch('builtins.input', side_effect=["x"]) |
|
|
def test_read_math_function_false_if_enter_x(self, mock_input): |
|
|
def test_read_math_function_false_if_enter_x(self, mock_input): |
|
|
result = read_math_function() |
|
|
result = read_math_function() |
|
|
self.assertFalse(result) |
|
|
self.assertFalse(result) |
|
|
|
|
|
|
|
|
@patch('builtins.input', side_effect=["c", "5"]) |
|
|
@patch('builtins.input', side_effect=["c", "5"]) |
|
|
def test_read_math_function_return5_if_enter_c_5(self, mock_input): |
|
|
def test_read_math_function_return5_if_enter_c_5(self, mock_input): |
|
|
self.assertEqual(read_math_function(), 5) |
|
|
self.assertEqual(read_math_function(), 5) |
|
|
|
|
|
|
|
|
def test_easy_function_wrong_type(self): |
|
|
def test_easy_function_wrong_type(self): |
|
|
self.assertEqual(simplify_easy_math_function("a", "42x"), False) |
|
|
self.assertEqual(simplify_easy_math_function("a", "42x"), False) |
|
|
|
|
|
|
|
|
def test_easy_function_number_as_function_return(self): |
|
|
def test_easy_function_number_as_function_return(self): |
|
|
self.assertEqual(simplify_easy_math_function("v", 42), 42) |
|
|
self.assertEqual(simplify_easy_math_function("v", 42), 42) |
|
|
|
|
|
|
|
|
def test_easy_function_string_is_constant(self): |
|
|
def test_easy_function_string_is_constant(self): |
|
|
self.assertEqual(simplify_easy_math_function("v", "42^(2)+1-3*4/3"), 1761) |
|
|
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): |
|
|
def test_extraction_linear_function_constant_without_math_operators_addition(self): |
|
|
self.assertEqual(extract_constant("42x+5"), ["5", "42x"]) |
|
|
self.assertEqual(extract_constant("42x+5"), ["5", "42x"]) |
|
|
|
|
|
|
|
|
def test_extraction_linear_function_constant_without_math_operators_subtraction(self): |
|
|
def test_extraction_linear_function_constant_without_math_operators_subtraction(self): |
|
|
self.assertEqual(extract_constant("42x-5"), ["-5", "42x"]) |
|
|
self.assertEqual(extract_constant("42x-5"), ["-5", "42x"]) |
|
|
|
|
|
|
|
|
def test_extraction_linear_function_no_constant(self): |
|
|
def test_extraction_linear_function_no_constant(self): |
|
|
self.assertEqual(extract_constant("42x"), ["0", "42x"]) |
|
|
self.assertEqual(extract_constant("42x"), ["0", "42x"]) |
|
|
|
|
|
|
|
|
def test_extraction_linear_function_constant_with_math_operators(self): |
|
|
def test_extraction_linear_function_constant_with_math_operators(self): |
|
|
self.assertEqual(extract_constant("42x+42^(2)+1-3*4/3"), ["42^(2)+1-3*4/3", "42x"]) |
|
|
self.assertEqual(extract_constant("42x+42^(2)+1-3*4/3"), ["42^(2)+1-3*4/3", "42x"]) |
|
|
|
|
|
|
|
|
def test_easy_function_linear_constant_gets_simplified(self): |
|
|
def test_easy_function_linear_constant_gets_simplified(self): |
|
|
self.assertEqual(simplify_easy_math_function("v", "42x+42^(2)+1-3*4/3"), [1761, "42x"]) |
|
|
self.assertEqual(simplify_easy_math_function("v", "42x+42^(2)+1-3*4/3"), [1761, "42x"]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
if __name__ == '__main__': |
|
|
unittest.main() |
|
|
unittest.main() |