diff --git a/.idea/PythonHomework.iml b/.idea/PythonHomework.iml
new file mode 100644
index 00000000..67116063
--- /dev/null
+++ b/.idea/PythonHomework.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml
new file mode 100644
index 00000000..0ef22171
--- /dev/null
+++ b/.idea/inspectionProfiles/Project_Default.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 00000000..32b11402
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 00000000..1d518fa3
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 00000000..94a25f7f
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 00000000..92272c9a
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,546 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ',',
+ function_result
+ numbers
+ was v
+ ????
+ Raises(ValueError
+ \'Formula was validated\! \'\n \'Errors were not found\.\'
+ 'Formula was validated! Errors were not found.'
+
+
+
+ Equal(True
+ False
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1559389504861
+
+
+ 1559389504861
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/final_task/config.py b/final_task/config.py
new file mode 100644
index 00000000..262fc758
--- /dev/null
+++ b/final_task/config.py
@@ -0,0 +1,50 @@
+import math
+import operator
+import string
+
+LETTERS = tuple(string.ascii_lowercase + string.ascii_uppercase)
+DIGITS = tuple(string.digits)
+
+UNARY_OPERATORS = {'+': (1, operator.add),
+ '-': (1, operator.sub),
+ }
+
+BINARY_OPERATORS = {'*': (2, operator.mul),
+ '/': (2, operator.truediv),
+ '//': (2, operator.floordiv),
+ '%': (2, operator.imod),
+ '^': (3, operator.ipow),
+ '<': (0, operator.lt),
+ '<=': (0, operator.le),
+ '>': (0, operator.gt),
+ '>=': (0, operator.ge),
+ '==': (0, operator.eq),
+ '!=': (0, operator.ne),
+ }
+
+OPERATORS = UNARY_OPERATORS.copy()
+OPERATORS.update(BINARY_OPERATORS)
+
+PARENTHESES = ('(', ')')
+
+OPERATORS_BEGIN = ('+', '-', '*', '/', '%', '^', '<', '>', '=', '!',)
+
+DOUBLE_OPER_PART1 = ('/', '<', '>', '=', '!',)
+DOUBLE_OPER_PART2 = ('/', '=',)
+
+BUILT_IN_FUNCTIONS = ('abs', 'round')
+NOT_SUPPORTED_MATH_FUNCTIONS = ('frexp', 'isclose', 'isinf', 'isfinite', 'isnan')
+MATH_CONSTS = ('e', 'pi', 'inf', 'nan', 'tau')
+MATH_FUNCTIONS = tuple([func for func in dir(math) if not func.startswith('_') and
+ func not in (MATH_CONSTS + NOT_SUPPORTED_MATH_FUNCTIONS)])
+
+ALL_FUNCTIONS = BUILT_IN_FUNCTIONS + MATH_FUNCTIONS
+ALL_FUNCTIONS_AND_CONSTS = ALL_FUNCTIONS + MATH_CONSTS
+
+ALL_FUNCTIONS_DICT = {el: (4,) for el in ALL_FUNCTIONS}
+ALL_FUNCTIONS_AND_OPERATORS_DICT = ALL_FUNCTIONS_DICT.copy()
+ALL_FUNCTIONS_AND_OPERATORS_DICT.update(OPERATORS)
+
+
+DELIMETERS = ('.', ',', ' ')
+ALLOWED_TOKENS = OPERATORS_BEGIN + LETTERS + DIGITS + PARENTHESES + DELIMETERS
diff --git a/final_task/pycalc.py b/final_task/pycalc.py
new file mode 100644
index 00000000..b897fe0f
--- /dev/null
+++ b/final_task/pycalc.py
@@ -0,0 +1,25 @@
+import argparse
+from sys import argv
+
+from pycalc_proc import PyCalcProcessing
+
+
+def create_parser():
+ parser_ = argparse.ArgumentParser(prog='Py Calc',
+ description='Pure-python command-line calculator',
+ epilog='(c) Alina Laevskaya 2019.'
+ )
+
+ parser_.add_argument('EXPRESSION', type=str, help='String formula for processing.')
+ return parser_
+
+
+def main():
+ parser = create_parser()
+ namespace = parser.parse_args(argv[1:])
+ py_calc_obj = PyCalcProcessing(namespace.EXPRESSION)
+ py_calc_obj.launch_processing()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/final_task/pycalc_proc.py b/final_task/pycalc_proc.py
new file mode 100644
index 00000000..cdcb0f12
--- /dev/null
+++ b/final_task/pycalc_proc.py
@@ -0,0 +1,392 @@
+# -*- coding: Windows-1251 -*-
+import inspect
+import re
+import builtins
+
+from config import *
+
+
+class PyCalcProcessing(object):
+
+ def __init__(self, formula_string):
+ self.formula_string = re.sub(' +', ' ', formula_string)
+
+ @staticmethod
+ def _matched_parentheses(el, count):
+ """
+ Counter for '(', ')'.
+
+ :param el (str): opening or closing parentheses
+ :param count (int): counter of parentheses
+ :return: count (int)
+ """
+ if el == "(":
+ count += 1
+ elif el == ")":
+ count -= 1
+ return count
+
+ @staticmethod
+ def pre_validate(formula_string):
+ """
+ Need to apply pre-validation of some errors before parsing to tokens fo more convenient
+ parsing in current version of implementation.
+
+ :param formula_string: input formula as text
+ :return: was_error
+ """
+ was_error = False
+ # check that formula is not empty
+ if not isinstance(formula_string, str) or not formula_string:
+ print('ERROR: Formula should be not empty string!')
+ return True
+ # check that there is not more than one delimiter in a row in the formula
+ # it's more convenient to do it here in order to simplify parsing to tokens
+ if '..' in formula_string:
+ print('ERROR: Number can not contain more than one delimiter "." !')
+ was_error = True
+ # check if there is whitespace between double operators
+ if re.search('/ /|< =|> =|= =|! =', formula_string):
+ print('ERROR: space is not allowed in operators: //, <=, >=, ==, !=.')
+ was_error = True
+ if re.search(r'\d\s\d', formula_string):
+ print('ERROR: space is not allowed between digits!')
+ was_error = True
+ # check allowed tokens
+ for el in formula_string.strip():
+ if el not in ALLOWED_TOKENS:
+ print('ERROR: Formula contains incorrect symbol "{}"'.format(el))
+ was_error = True
+ return was_error
+
+ @staticmethod
+ def parse(formula_string):
+ """
+ Parsing formula to tokens
+
+ :param formula_string: input formula as text which have passed pre-validation
+ :return: None
+ """
+ number = op = function = ''
+ for el in formula_string.strip():
+ if el in LETTERS: # function processing
+ function += el.lower()
+ if op: # shot the operator if it has been accumulated
+ yield op
+ op = ''
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ number = ''
+ elif el in string.digits + '.': # processing integers and floats
+ if function:
+ function += el # continue to accumulate the function until meet something different from the number
+ else:
+ number += el
+ if op: # shot the operator if has been accumulated
+ yield op
+ op = ''
+ if function: # shot the function if it has been accumulated
+ yield function
+ function = ''
+ elif el in OPERATORS_BEGIN: # operator processing
+ if el in DOUBLE_OPER_PART1 and not op: # if double operator is possible, add and wait
+ op += el
+ elif el in DOUBLE_OPER_PART2 and op: # found double
+ op += el
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ number = ''
+ if function: # shot the function if it has been accumulated
+ yield function
+ function = ''
+ yield op # shot an double operator when it was accumulated
+ op = ''
+ else: # if the operator is single
+ if op: # if it was accumulated at the previous step - shot, reset
+ yield op
+ op = ''
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ number = ''
+ if function: # shot the function if it has been accumulated
+ yield function
+ function = ''
+ yield el # hit a single operator
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ number = ''
+ if function: # shot the function if it has been accumulated
+ yield function
+ function = ''
+ elif el in PARENTHESES + (',',): # handling brackets and commas (if a function with multiple arguments)
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ number = ''
+ if function: # shot the function if it has been accumulated
+ yield function
+ function = ''
+ if op: # shot the operator if has been accumulated
+ yield op
+ op = ''
+ yield el # shot brace or comma as soon as they are met
+
+ if function: # shot the function if it has been accumulated
+ yield function
+ if number: # shot number if it was accumulated
+ yield float(number) if number != '.' else '.'
+ if op: # shot the operator if it has been accumulated
+ yield op
+
+ def validate_parsed_list(self, parsed_list):
+ """
+ Validation of various errors before polish sorting
+
+ :param parsed_list: list with tokens of pre-validated and parsed formula for validation
+ :return: was_error
+ """
+ was_error = False
+ counter = 0 # counter for parentheses
+ was_number = False
+ previous_el = ''
+
+ if parsed_list[-1] in OPERATORS:
+ print('ERROR: Operator at the end of the formula: "{}" '.format(parsed_list[-1]))
+ was_error = True
+ if parsed_list[0] in BINARY_OPERATORS:
+ print('ERROR: Formula can not start with binary operator "{}"'.format(parsed_list[0]))
+ was_error = True
+
+ for el in parsed_list:
+ counter = self._matched_parentheses(el, counter)
+
+ message = 'ERROR: After {} element {} is forbidden!'.format(str(previous_el), str(el))
+
+ if isinstance(el, float) or el in MATH_CONSTS and was_number is False:
+ was_number = True
+
+ if el == '.':
+ print('ERROR: Single delimiter is prohibited in formula!')
+ was_error = True
+
+ if isinstance(el, str) and el[0] in LETTERS:
+ if el.lower() not in ALL_FUNCTIONS_AND_CONSTS:
+ print('ERROR: Function or constant {} is not supported by calculator'.format(el))
+ was_error = True
+
+ if previous_el == '(':
+ if el in ((')', ',',) + tuple(BINARY_OPERATORS.keys())):
+ print(message)
+ was_error = True
+
+ if previous_el == ')':
+ if el in (('(',) + ALL_FUNCTIONS_AND_CONSTS) or isinstance(el, float):
+ print(message)
+ was_error = True
+
+ if previous_el == ',':
+ if el in (')', ',', '.'):
+ print(message)
+ was_error = True
+
+ if previous_el in UNARY_OPERATORS:
+ if el in ((')', ',',) + tuple(BINARY_OPERATORS.keys())):
+ print(message)
+
+ if previous_el in BINARY_OPERATORS:
+ if el in ((')', ',',) + tuple(BINARY_OPERATORS.keys())):
+ print(message)
+ was_error = True
+
+ if previous_el in ALL_FUNCTIONS:
+ if el != '(':
+ print(message)
+ was_error = True
+
+ if isinstance(previous_el, float) or previous_el in MATH_CONSTS:
+ if el in (('(',) + ALL_FUNCTIONS_AND_CONSTS) or isinstance(el, float):
+ print(message)
+ was_error = True
+
+ previous_el = el
+
+ if counter != 0:
+ print('ERROR: Wrong number of opened or closed parentheses in formula!')
+ was_error = True
+
+ if was_number is False:
+ print('ERROR: Formula does not contain numbers!')
+ was_error = True
+
+ return was_error
+
+ @staticmethod
+ def process_unary_operations(validated_list):
+ """
+ :param validated_list: list of tokens after parsing of input formula and validation of it
+ :return: processed_list: all unary '+' are removed, all redundant unary '-' are removed
+ """
+ stack_str = ''
+ processed_list = []
+ for el in validated_list:
+ if el in UNARY_OPERATORS:
+ stack_str += el
+ else:
+ is_unary_plus = ((processed_list and processed_list[-1]
+ in (('(', ',') + tuple(BINARY_OPERATORS.keys()))) or not processed_list)
+ if stack_str:
+ if '-' in stack_str:
+ if stack_str.count('-') % 2 == 0: # count the number of minuses, replacing with plus or minus
+ if is_unary_plus:
+ stack_str = ''
+ else:
+ stack_str = '+'
+ else:
+ stack_str = '-'
+ else:
+ if is_unary_plus:
+ stack_str = ''
+ else:
+ stack_str = '+'
+ if stack_str:
+ processed_list.append(stack_str)
+ stack_str = ''
+ processed_list.append(el)
+ return processed_list
+
+ @staticmethod
+ def sort_to_polish(parsed_formula):
+ """
+ Implementing polish sorting needed for calculating the result
+
+ :param parsed_formula: list that passed validation with tokens of parsed formula
+ :return: None
+ """
+ stack = [] # use list as stack
+ previous_token = ''
+ for token in parsed_formula:
+ # if the element is an operator, then we send further all the operators from the stack,
+ # whose priority is greater than or equal to the newcomer,
+ # up to the opening bracket or the stack is empty.
+ if token in ALL_FUNCTIONS_AND_OPERATORS_DICT:
+ if token == '-' and previous_token in ('(', ',', '') + tuple(BINARY_OPERATORS.keys()):
+ yield 0.0
+ stack.append(token)
+ else:
+ while (stack and stack[-1] != "(" and
+ ALL_FUNCTIONS_AND_OPERATORS_DICT[token][0] <= ALL_FUNCTIONS_AND_OPERATORS_DICT[stack[-1]][0]
+ and token != '^'):
+ yield stack.pop()
+ stack.append(token)
+ elif token == ")":
+ # if the element is a closing bracket, we give all the elements from the stack,
+ # up to the opening bracket, and throw away the opening bracket out of the stack.
+ while stack:
+ x = stack.pop()
+ if x == "(":
+ break
+ yield x
+ elif token == "(":
+ # if the element is an opening bracket, just put it to the stack
+ stack.append(token)
+ elif token == ",": # end of argument
+ # give all operators from the stack to the opening bracket
+ while stack and stack[-1] != "(":
+ yield stack.pop()
+ else:
+ # if the element is a number or a constant, send it immediately to the output
+ yield token
+ previous_token = token
+ while stack:
+ yield stack.pop()
+
+ @staticmethod
+ def _get_num_args(func):
+ if inspect.isfunction(func):
+ return len(inspect.getfullargspec(func).args)
+ else:
+ spec = func.__doc__.split('\n')[0]
+ args = spec[spec.find('(') + 1:spec.find(')')]
+ return args.count(',') + 1 if args else 0
+
+ def calc(self, polish_list):
+ """
+ Calculating the result after polish sorting
+
+ :param polish_list: list that have been polish-sorted
+ :return: stack[0]: the result of calculation
+ """
+ stack = []
+ function_result = None
+
+ for token in polish_list:
+ if token in MATH_FUNCTIONS:
+ arguments = []
+ func_name = getattr(math, token)
+
+ if func_name != math.log:
+ number_of_args = self._get_num_args(func_name)
+ for i in range(number_of_args):
+ if stack:
+ arguments.insert(0, stack.pop())
+ else:
+ # since log has a changing number of arguments, separate processing
+ index_current_log_token = polish_list.index(token)
+ try:
+ next_token_after_log = polish_list[index_current_log_token + 1]
+ except IndexError:
+ next_token_after_log = ''
+
+ if next_token_after_log in OPERATORS and len(stack) == 2:
+ arguments.insert(0, stack.pop())
+ else:
+ if len(stack) >= 2:
+ arguments.insert(0, stack.pop())
+ arguments.insert(0, stack.pop())
+ else:
+ arguments.insert(0, stack.pop())
+
+ try:
+ function_result = func_name(*tuple(arguments))
+ except TypeError:
+ print('ERROR: Formula contains incorrect number of arguments in function.')
+
+ stack.append(function_result) # calculate the operator, return to the stack
+ arguments = []
+
+ elif token in BUILT_IN_FUNCTIONS:
+ x = stack.pop() # take one number from the stack
+ func_name = getattr(builtins, token)
+ stack.append(func_name(x))
+ elif token in OPERATORS: # if the incoming element is an operator,
+ y, x = stack.pop(), stack.pop() # pick up two numbers from the stack
+ stack.append(OPERATORS[token][1](x, y)) # calculate the operator, return to the stack
+ elif token in MATH_CONSTS:
+ stack.append(getattr(math, token))
+ else:
+ stack.append(token)
+
+ if len(stack) > 1:
+ print('ERROR: Formula contains incorrect number of arguments in function.')
+
+ return stack[0] # the result of the calculation is the only item on the stack
+
+ def launch_processing(self):
+ """
+ Launch of program
+
+ :param self
+ :return: None
+ """
+ parsed_list = []
+ polish_list = []
+ was_error = self.pre_validate(self.formula_string)
+ if not was_error:
+ for el in self.parse(self.formula_string):
+ parsed_list.append(el)
+ was_error = self.validate_parsed_list(parsed_list)
+ if not was_error:
+ parsed_list = self.process_unary_operations(parsed_list)
+ for el in self.sort_to_polish(parsed_list):
+ polish_list.append(el)
+ result = self.calc(polish_list)
+ print(result)
diff --git a/final_task/setup.py b/final_task/setup.py
index e69de29b..d345fdc7 100644
--- a/final_task/setup.py
+++ b/final_task/setup.py
@@ -0,0 +1,12 @@
+from setuptools import setup
+
+setup(
+ name='pycalc',
+ version='1.0',
+ description='Pure-python command-line calculator.',
+ url='',
+ author='Layeuskaya Alina',
+ author_email='cool.girl.alina@mail.ru',
+ py_modules=['pycalc', 'config', 'pycalc_proc'],
+ entry_points={'console_scripts': ['pycalc=pycalc:main', ], },
+)
diff --git a/final_task/unittests/unittest_process_unary_operations.py b/final_task/unittests/unittest_process_unary_operations.py
new file mode 100644
index 00000000..1ac9d4cc
--- /dev/null
+++ b/final_task/unittests/unittest_process_unary_operations.py
@@ -0,0 +1,151 @@
+import unittest
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+calc_obj = PyCalcProcessing('1')
+
+
+class TestProcessUnaryOperations(unittest.TestCase):
+ def test1(self):
+ list_ = calc_obj.process_unary_operations(['-', 13.0, ])
+ self.assertEqual(list_, ['-', 13.0])
+
+ def test2(self):
+ list_ = calc_obj.process_unary_operations(['+', 13.0, ])
+ self.assertEqual(list_, [13.0])
+
+ def test3(self):
+ list_ = calc_obj.process_unary_operations(['-', '-', 13.0, ])
+ self.assertEqual(list_, [13.0])
+
+ def test4(self):
+ list_ = calc_obj.process_unary_operations(['-', '-', '-', 13.0, ])
+ self.assertEqual(list_, ['-', 13.0])
+
+ def test5(self):
+ list_ = calc_obj.process_unary_operations(['-', '-', '-', '-', 13.0, ])
+ self.assertEqual(list_, [13.0])
+
+ def test6(self):
+ list_ = calc_obj.process_unary_operations(['+', '-', '+', '+', 13.0, ])
+ self.assertEqual(list_, ['-', 13.0])
+
+ def test7(self):
+ list_ = calc_obj.process_unary_operations(['-', '(', '-', 13.0, ')'])
+ self.assertEqual(list_, ['-', '(', '-', 13.0, ')'])
+
+ def test8(self):
+ list_ = calc_obj.process_unary_operations(['-', '(', '-', '-', 13.0, ')'])
+ self.assertEqual(list_, ['-', '(', 13.0, ')'])
+
+ def test9(self):
+ list_ = calc_obj.process_unary_operations(['+', '+', '+', '+', 13.0, ])
+ self.assertEqual(list_, [13.0])
+
+ def test10(self):
+ list_ = calc_obj.process_unary_operations([1.0, '*', '-', '-', 13.0, ])
+ self.assertEqual(list_, [1.0, '*', 13.0])
+
+ def test11(self):
+ list_ = calc_obj.process_unary_operations([1.0, '*', '-', 13.0, ])
+ self.assertEqual(list_, [1.0, '*', '-', 13.0])
+
+ def test12(self):
+ list_ = calc_obj.process_unary_operations([1.0, '*', '+', 13.0, ])
+ self.assertEqual(list_, [1.0, '*', 13.0])
+
+ def test13(self):
+ list_ = calc_obj.process_unary_operations([1.0, '*', '(', '+', 13.0, ')'])
+ self.assertEqual(list_, [1.0, '*', '(', 13.0, ')'])
+
+ def test14(self):
+ list_ = calc_obj.process_unary_operations(['(', 1.0, '+', 13.0, ')'])
+ self.assertEqual(list_, ['(', 1.0, '+', 13.0, ')'])
+
+ def test15(self):
+ list_ = calc_obj.process_unary_operations(['-', '-', '-', '-', '-', 1.0, '-', '+', '(', '-', 1.0, ')'])
+ self.assertEqual(list_, ['-', 1.0, '-', '(', '-', 1.0, ')'])
+
+ def test16(self):
+ list_ = calc_obj.process_unary_operations(['-', '+', '-', '-', '-', '+', '-', 1.0])
+ self.assertEqual(list_, ['-', 1.0])
+
+ def test17(self):
+ list_ = calc_obj.process_unary_operations(['-', '+', '-', '+', '-', '+', '-', '+', '-', '+', '-', 1.0])
+ self.assertEqual(list_, [1.0])
+
+ def test18(self):
+ list_ = calc_obj.process_unary_operations(['-', '+', '(', '-', '-', '+', '-', 1.0, ')'])
+ self.assertEqual(list_, ['-', '(', '-', 1.0, ')'])
+
+ def test19(self):
+ list_ = calc_obj.process_unary_operations(['+', '+', '-', '-', '+', '+', '-', '(', '-', 1.0, ')'])
+ self.assertEqual(list_, ['-', '(', '-', 1.0, ')'])
+
+ def test20(self):
+ list_ = calc_obj.process_unary_operations([1, '-', '-', '-', 1.0])
+ self.assertEqual(list_, [1.0, '-', 1.0])
+
+ def test21(self):
+ list_ = calc_obj.process_unary_operations([1.0, '-', '-', 1.0, '-', '-', 1.0])
+ self.assertEqual(list_, [1.0, '+', 1.0, '+', 1.0])
+
+ def test22(self):
+ list_ = calc_obj.process_unary_operations([1.0, '-', '+', 1.0, '+', '-', 1.0])
+ self.assertEqual(list_, [1.0, '-', 1.0, '-', 1.0])
+
+ def test23(self):
+ list_ = calc_obj.process_unary_operations(['+', '+', '+', '+', '+', 1.0])
+ self.assertEqual(list_, [1.0])
+
+ def test24(self):
+ list_ = calc_obj.process_unary_operations(['-', '-', '-', '-', '-', 1.0])
+ self.assertEqual(list_, ['-', 1.0])
+
+ def test25(self):
+ list_ = calc_obj.process_unary_operations(['+', '+', '(', '+', '(', '+', '+', 1.0, ')', ')'])
+ self.assertEqual(list_, ['(', '(', 1.0, ')', ')'])
+
+ def test26(self):
+ list_ = calc_obj.process_unary_operations(['-', '(', '-', '+', '(', '-', '+', 1.0, ')', ')'])
+ self.assertEqual(list_, ['-', '(', '-', '(', '-', 1.0, ')', ')'])
+
+ def test27(self):
+ list_ = calc_obj.process_unary_operations(['+', 1.0, ])
+ self.assertEqual(list_, [1.0])
+
+ def test28(self):
+ list_ = calc_obj.process_unary_operations([6.0, '-', '(', '-', 13.0, ')'])
+ self.assertEqual(list_, [6.0, '-', '(', '-', 13.0, ')'])
+
+ def test29(self):
+ list_ = calc_obj.process_unary_operations([1.0, '-', '-', '-', 1.0])
+ self.assertEqual(list_, [1.0, '-', 1.0])
+
+ def test30(self):
+ list_ = calc_obj.process_unary_operations(['-', '+', '-', '-', '-', '+', '-', 1.0])
+ self.assertEqual(list_, ['-', 1.0])
+
+ def test31(self):
+ list_ = calc_obj.process_unary_operations(
+ ['sin', '(', '-', 'cos', '(', '-', 'sin', '(', 3.0, ')', '-', 'cos', '(', '-',
+ 'sin', '(', '-', 3.0, '*', 5.0, ')', '-', 'sin', '(', 'cos', '(', 'log10',
+ '(', 43.0, ')', ')', ')', ')', '+', 'cos', '(', 'sin', '(', 'sin', '(', 34.0,
+ '-', 2.0, '^', 2.0, ')', ')', ')', ')', '-', '-', 'cos', '(', 1.0, ')', '-',
+ '-', 'cos', '(', 0.0, ')', '^', 3.0, ')'])
+ self.assertEqual(list_, ['sin', '(', '-', 'cos', '(', '-', 'sin', '(', 3.0, ')', '-', 'cos', '(', '-', 'sin',
+ '(', '-', 3.0, '*', 5.0, ')', '-', 'sin', '(', 'cos', '(', 'log10', '(', 43.0, ')',
+ ')', ')', ')', '+', 'cos', '(', 'sin', '(', 'sin', '(', 34.0, '-', 2.0, '^', 2.0, ')',
+ ')', ')', ')', '+', 'cos', '(', 1.0, ')', '+', 'cos', '(', 0.0, ')', '^', 3.0, ')'])
+
+ def test32(self):
+ list_ = calc_obj.process_unary_operations(
+ [10.0, '*', 'e', '^', 0.0, '*', 'log10', '(', 0.4, '-', 5.0, '/', '-', 0.1,
+ '-', 10.0, ')', '-', '-', 'abs', '(', '-', 53.0, '/', 10.0, ')', '+', '-',
+ 5.0])
+ self.assertEqual(list_, [10.0, '*', 'e', '^', 0.0, '*', 'log10', '(', 0.4, '-', 5.0, '/', '-', 0.1, '-',
+ 10.0, ')', '+', 'abs', '(', '-', 53.0, '/', 10.0, ')', '-', 5.0])
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/final_task/unittests/unittests_calc.py b/final_task/unittests/unittests_calc.py
new file mode 100644
index 00000000..4286200b
--- /dev/null
+++ b/final_task/unittests/unittests_calc.py
@@ -0,0 +1,303 @@
+# -*- coding: Windows-1251 -*-
+import unittest
+import math
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+calc_obj = PyCalcProcessing('1')
+
+
+class TestCalcing(unittest.TestCase):
+
+ # Unary operators
+ def test1(self):
+ self.assertEqual(-13.0, calc_obj.calc([0.0, 13.0, '-']))
+
+ def test2(self):
+ self.assertEqual(6.0 - (-13.0), calc_obj.calc([6.0, 0.0, 13.0, '-', '-']))
+
+ def test3(self):
+ self.assertEqual(1.0---1.0, calc_obj.calc([1.0, 1.0, '-']))
+
+ def test4(self):
+ self.assertEqual(-+---+-1.0, calc_obj.calc([0.0, 1.0, '-']))
+
+ def test5(self):
+ self.assertEqual(1.0 + 2.0 * 2.0, calc_obj.calc([1.0, 2.0, 2.0, '*', '+']))
+
+ def test6(self):
+ self.assertEqual(1.0 + (2.0 + 3.0 * 2.0) * 3.0, calc_obj.calc([1.0, 2.0, 3.0, 2.0, '*', '+', 3.0, '*', '+']))
+
+ def test7(self):
+ self.assertEqual(10.0 * (2.0 + 1.0), calc_obj.calc([10.0, 2.0, 1.0, '+', '*']))
+
+ def test8(self):
+ self.assertEqual(10.0 ** (2.0 + 1.0), calc_obj.calc([10.0, 2.0, 1.0, '+', '^']))
+
+ def test9(self):
+ self.assertEqual(100.0 / 3.0 ** 2.0, calc_obj.calc([100.0, 3.0, 2.0, '^', '/']))
+
+ def test10(self):
+ self.assertEqual(100.0 / 3.0 % 2.0 ** 2.0, calc_obj.calc([100.0, 3.0, '/', 2.0, 2.0, '^', '%']))
+
+ # Functions and constants
+ def test11(self):
+ self.assertEqual(math.pi + math.e, calc_obj.calc(['pi', 'e', '+']))
+
+ def test12(self):
+ self.assertEqual(math.log(math.e), calc_obj.calc(['e', 'log']))
+
+ def test13(self):
+ self.assertEqual(math.sin(math.pi / 2.0), calc_obj.calc(['pi', 2.0, '/', 'sin']))
+
+ def test14(self):
+ self.assertEqual(math.log10(100.0), calc_obj.calc([100.0, 'log10']))
+
+ def test15(self):
+ self.assertEqual(math.sin(math.pi / 2.0) * 111 * 6,
+ calc_obj.calc(['pi', 2.0, '/', 'sin', 111.0, '*', 6.0, '*']))
+
+ def test16(self):
+ self.assertEqual(2.0 * math.sin(math.pi / 2.0), calc_obj.calc([2.0, 'pi', 2.0, '/', 'sin', '*']))
+
+ def test17(self):
+ self.assertEqual(abs(-5.0), calc_obj.calc([0.0, 5.0, '-', 'abs']))
+
+ def test18(self):
+ self.assertEqual(round(123.456789), calc_obj.calc([123.456789, 'round']))
+
+ # Associative
+ def test19(self):
+ self.assertEqual(102.0 % 12.0 % 7.0, calc_obj.calc([102.0, 12.0, '%', 7.0, '%']))
+
+ def test20(self):
+ self.assertEqual(100.0 / 4.0 / 3.0, calc_obj.calc([100.0, 4.0, '/', 3.0, '/']))
+
+ def test21(self):
+ self.assertEqual(2.0 ** 3.0 ** 4.0, calc_obj.calc([2.0, 3.0, 4.0, '^', '^']))
+
+ # Comparison operators
+ def test22(self):
+ self.assertEqual(1.0 + 2.0 * 3.0 == 1.0 + 2.0 * 3.0,
+ calc_obj.calc([1.0, 2.0, 3.0, '*', '+', 1.0, 2.0, 3.0, '*', '+', '==']))
+
+ def test23(self):
+ self.assertEqual(math.e ** 5.0 >= math.e ** 5.0 + 1.0,
+ calc_obj.calc(['e', 5.0, '^', 'e', 5.0, '^', 1.0, '+', '>=']))
+
+ def test24(self):
+ self.assertEqual(1.0 + 2.0 * 4.0 / 3.0 + 1.0 != 1.0 + 2.0 * 4.0 / 3.0 + 2.0,
+ calc_obj.calc([1.0, 2.0, 4.0, '*', 3.0, '/', '+', 1.0, '+', 1.0, 2.0, 4.0, '*', 3.0, '/', '+',
+ 2.0, '+', '!=']))
+
+ # Common tests
+ def test25(self):
+ self.assertEqual((100.0), calc_obj.calc([100.0]))
+
+ def test26(self):
+ self.assertEqual(666.0, calc_obj.calc([666.0]))
+
+ def test27(self):
+ self.assertEqual(-.1, calc_obj.calc([0.0, 0.1, '-']))
+
+ def test28(self):
+ self.assertEqual(1.0 / 3.0, calc_obj.calc([1.0, 3.0, '/']))
+
+ def test29(self):
+ self.assertEqual(1.0 / 3.0, calc_obj.calc([1.0, 3.0, '/']))
+
+ def test30(self):
+ self.assertEqual(.1*2.0**56.0, calc_obj.calc([0.1, 2.0, 56.0, '^', '*']))
+
+ def test31(self):
+ self.assertEqual(math.e ** 34.0, calc_obj.calc(['e', 34.0, '^']))
+
+ def test32(self):
+ self.assertEqual((2.0 ** (math.pi/math.pi+math.e/math.e+2.0**0.0)),
+ calc_obj.calc([2.0, 'pi', 'pi', '/', 'e', 'e', '/', '+', 2.0, 0.0, '^', '+', '^']))
+
+ def test33(self):
+ self.assertEqual((2.0**(math.pi/math.pi+math.e/math.e+2.0**0.0))**(1.0/3.0), calc_obj.calc(
+ [2.0, 'pi', 'pi', '/', 'e', 'e', '/', '+', 2.0, 0.0, '^', '+', '^', 1.0, 3.0, '/', '^']))
+
+ def test34(self):
+ self.assertEqual(math.sin(math.pi/2.0**1.0) + math.log(1*4+2**2+1, 3**2),
+ calc_obj.calc(['pi', 2.0, 1.0, '^', '/', 'sin', 1.0, 4.0, '*', 2.0, 2.0, '^',
+ '+', 1.0, '+', 3.0, 2.0, '^', 'log', '+']))
+
+ def test35(self):
+ self.assertEqual(10.0*math.e**0.0*math.log10(.4 - 5.0 / -0.1-10.0) - -abs(-53.0/10.0) + -5.0,
+ calc_obj.calc([10.0, 'e', 0.0, '^', '*', 0.4, 5.0, 0.0, 0.1, '-', '/', '-', 10.0,
+ '-', 'log10', '*', 0.0, 53.0, 10.0, '/', '-', 'abs', '+', 5.0, '-']))
+
+ def test36(self):
+ self.assertEqual(
+ math.sin(-math.cos(-math.sin(3.0)-math.cos(-math.sin(-3.0*5.0)-math.sin(math.cos(math.log10(43.0)))) +
+ math.cos(math.sin(math.sin(34.0-2.0**2.0))))--math.cos(1.0)--math.cos(0.0)**3.0),
+ calc_obj.calc([0.0, 0.0, 3.0, 'sin', '-', 0.0, 0.0, 3.0, 5.0, '*', '-', 'sin', '-', 43.0, 'log10', 'cos',
+ 'sin', '-', 'cos', '-', 34.0, 2.0, 2.0, '^', '-', 'sin', 'sin', 'cos', '+', 'cos', '-', 1.0,
+ 'cos', '+', 0.0, 3.0, '^', 'cos', '+', 'sin']))
+
+ def test37(self):
+ self.assertEqual(2.0**(2.0**2.0*2.0**2.0), calc_obj.calc([2.0, 2.0, 2.0, '^', 2.0, 2.0, '^', '*', '^']))
+
+ def test38(self):
+ self.assertEqual(math.sin(math.e**math.log(math.e**math.e**math.sin(23.0), 45.0) +
+ math.cos(3.0+math.log10(math.e**-math.e))),
+ calc_obj.calc(['e', 'e', 'e', 23.0, 'sin', '^', '^', 45.0, 'log', '^', 3.0, 'e', 0.0,
+ 'e', '-', '^', 'log10', '+', 'cos', '+', 'sin']))
+
+ # Self-made cases
+ def test52(self):
+ self.assertEqual(100.0/3.0, calc_obj.calc([100.0, 3.0, '/']))
+
+ def test54(self):
+ self.assertEqual(100.0+3.0, calc_obj.calc([100.0, 3.0, '+']))
+
+ def test55(self):
+ self.assertEqual(100.0//3.0, calc_obj.calc([100.0, 3.0, '//']))
+
+ def test56(self):
+ self.assertEqual(math.sin(math.sin(1.0)), calc_obj.calc([1.0, 'sin', 'sin']))
+
+ def test57(self):
+ self.assertEqual(math.sin(math.sin(1.0))+1.0+math.sin(1.0),
+ calc_obj.calc([1.0, 'sin', 'sin', 1.0, '+', 1.0, 'sin', '+']))
+
+ def test58(self):
+ self.assertEqual(abs(-3.0), calc_obj.calc([0.0, 3.0, '-', 'abs']))
+
+ def test59(self):
+ self.assertEqual(round(3.56393), calc_obj.calc([3.56393, 'round']))
+
+ def test60(self):
+ self.assertEqual(abs(-round(3.56393)), calc_obj.calc([0.0, 3.56393, 'round', '-', 'abs']))
+
+ # logarithms
+ def test61(self):
+ self.assertEqual(math.log(8.0, 2.0), calc_obj.calc([8.0, 2.0, 'log']))
+
+ def test62(self):
+ self.assertEqual(math.log(2.7), calc_obj.calc([2.7, 'log']))
+
+ def test63(self):
+ self.assertEqual((math.log(8.0, 2.0)-1.0)-2.0, calc_obj.calc([8.0, 2.0, 'log', 1.0, '-', 2.0, '-']))
+
+ def test64(self):
+ self.assertEqual(-math.log(8.0, 2.0), calc_obj.calc([0.0, 8.0, 2.0, 'log', '-']))
+
+ def test65(self):
+ self.assertEqual(math.log(8.0, 2.0)-1.0, calc_obj.calc([8.0, 2.0, 'log', 1.0, '-']))
+
+ def test66(self):
+ self.assertEqual(math.log(8.0, 2.0)*math.log(16.0, 2.0),
+ calc_obj.calc([8.0, 2.0, 'log', 16.0, 2.0, 'log', '*']))
+
+ def test67(self):
+ self.assertEqual(math.sin(math.log(8.0, 2.0)*math.log(16.0, 2.0)),
+ calc_obj.calc([8.0, 2.0, 'log', 16.0, 2.0, 'log', '*', 'sin']))
+
+ def test68(self):
+ self.assertEqual(math.log(8.0+20.0-1.0, 2.0+1.0),
+ calc_obj.calc([8.0, 20.0, '+', 1.0, '-', 2.0, 1.0, '+', 'log']))
+
+ def test69(self):
+ self.assertEqual(math.log10(100.0), calc_obj.calc([100.0, 'log10']))
+
+ def test70(self):
+ self.assertEqual(math.log(100.0, 10.0), calc_obj.calc([100.0, 10.0, 'log']))
+
+ def test71(self):
+ self.assertEqual((math.log10(100.0)-1.0)-2.0, calc_obj.calc([100.0, 'log10', 1.0, '-', 2.0, '-']))
+
+ def test72(self):
+ self.assertEqual(-math.log10(100.0), calc_obj.calc([0.0, 100.0, 'log10', '-']))
+
+ def test73(self):
+ self.assertEqual(math.log10(100.0)-1.0, calc_obj.calc([100.0, 'log10', 1.0, '-']))
+
+ def test74(self):
+ self.assertEqual(math.log10(100.0)*math.log10(1000.0), calc_obj.calc([100.0, 'log10', 1000.0, 'log10', '*']))
+
+ def test75(self):
+ self.assertEqual(math.sin(math.log10(100.0)*math.log10(1000.0)),
+ calc_obj.calc([100.0, 'log10', 1000.0, 'log10', '*', 'sin']))
+
+ def test76(self):
+ self.assertEqual(math.log10(800.0/2.0/4.0), calc_obj.calc([800.0, 2.0, '/', 4.0, '/', 'log10']))
+
+ # pow
+ def test77(self):
+ self.assertEqual(math.pow(2.0, 4.0), calc_obj.calc([2.0, 4.0, 'pow']))
+
+ def test78(self):
+ self.assertEqual(math.log(math.pow(10.0, 2.0), 10), calc_obj.calc([10.0, 2.0, 'pow', 10.0, 'log']))
+
+ def test79(self):
+ self.assertEqual((math.pow(2.0, 4.0)-1.0)-2.0, calc_obj.calc([2.0, 4.0, 'pow', 1.0, '-', 2.0, '-']))
+
+ def test80(self):
+ self.assertEqual(-math.pow(2.0, 4.0), calc_obj.calc([0.0, 2.0, 4.0, 'pow', '-']))
+
+ def test81(self):
+ self.assertEqual(math.pow(2.0, 4.0)-1.0, calc_obj.calc([2.0, 4.0, 'pow', 1.0, '-']))
+
+ def test82(self):
+ self.assertEqual(math.pow(2.0, 4.0)*math.pow(2.0, 3.0), calc_obj.calc([2.0, 4.0, 'pow', 2.0, 3.0, 'pow', '*']))
+
+ def test83(self):
+ self.assertEqual(math.sin(math.pow(2.0, 4.0)*math.pow(2.0, 3.0)),
+ calc_obj.calc([2.0, 4.0, 'pow', 2.0, 3.0, 'pow', '*', 'sin']))
+
+ def test84(self):
+ self.assertEqual(math.pow(2.0**(2.0**2.0*2.0**2.0), math.log10(100.0)*math.log10(1000.0)),
+ calc_obj.calc([2.0, 2.0, 2.0, '^', 2.0, 2.0, '^', '*', '^',
+ 100.0, 'log10', 1000.0, 'log10', '*', 'pow']))
+
+ def test85(self):
+ self.assertEqual(13.0, calc_obj.calc([13.0]))
+
+ def test86(self):
+ self.assertEqual(-(-13.0), calc_obj.calc([0.0, 0.0, 13.0, '-', '-']))
+
+ def test87(self):
+ self.assertEqual(-(13.0), calc_obj.calc([0.0, 13.0, '-']))
+
+ def test88(self):
+ self.assertEqual(1.0*-13.0, calc_obj.calc([1.0, 0.0, 13.0, '-', '*']))
+
+ def test89(self):
+ self.assertEqual(1.0*(-13.0), calc_obj.calc([1.0, 0.0, 13.0, '-', '*']))
+
+ def test90(self):
+ self.assertEqual(1.0*(13.0), calc_obj.calc([1.0, 13.0, '*']))
+
+ def test91(self):
+ self.assertEqual((1.0+13.0), calc_obj.calc([1.0, 13.0, '+']))
+
+ def test92(self):
+ self.assertEqual(-1.0-(-1.0), calc_obj.calc([0.0, 1.0, '-', 0.0, 1.0, '-', '-']))
+
+ def test93(self):
+ self.assertEqual(((1.0)), calc_obj.calc([1.0]))
+
+ def test94(self):
+ self.assertEqual(-(-(-1.0)), calc_obj.calc([0.0, 0.0, 0.0, 1.0, '-', '-', '-']))
+
+
+class TestCalcNegativeCases(unittest.TestCase):
+ def test1(self):
+ self.assertRaises(ValueError, lambda: calc_obj.calc([1.0, 2.0, 'sin']))
+
+ def test2(self):
+ self.assertRaises(ValueError, lambda: calc_obj.calc([1.0, 2.0, 3.0, 'sin']))
+
+ def test3(self):
+ self.assertRaises(ValueError, lambda: calc_obj.calc([1.0, 'pow']))
+
+ def test4(self):
+ self.assertRaises(ValueError, lambda: calc_obj.calc([1.0, 2.0, 3.0, 'pow']))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/final_task/unittests/unittests_parse_function.py b/final_task/unittests/unittests_parse_function.py
new file mode 100644
index 00000000..ae86b19d
--- /dev/null
+++ b/final_task/unittests/unittests_parse_function.py
@@ -0,0 +1,538 @@
+import unittest
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+
+calc_obj = PyCalcProcessing('1')
+
+
+class TestParsingPositiveCases(unittest.TestCase):
+
+ # Unary operators
+ def test1(self):
+ list_ = []
+ for el in calc_obj.parse('-13'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', 13.0])
+
+ def test2(self):
+ list_ = []
+ for el in calc_obj.parse('6-(-13)'):
+ list_.append(el)
+ self.assertEqual(list_, [6.0, '-', '(', '-', 13.0, ')'])
+
+ def test3(self):
+ list_ = []
+ for el in calc_obj.parse('1---1'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '-', '-', '-', 1.0])
+
+ def test4(self):
+ list_ = []
+ for el in calc_obj.parse('-+---+-1'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', '+', '-', '-', '-', '+', '-', 1.0])
+
+ # Operation priority
+ def test5(self):
+ list_ = []
+ for el in calc_obj.parse('1+2*2'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '+', 2.0, '*', 2.0])
+
+ def test6(self):
+ list_ = []
+ for el in calc_obj.parse('1+(2+3*2)*3'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '+', '(', 2.0, '+', 3.0, '*', 2.0, ')', '*', 3.0])
+
+ def test7(self):
+ list_ = []
+ for el in calc_obj.parse('10*(2+1)'):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, '*', '(', 2.0, '+', 1.0, ')'])
+
+ def test8(self):
+ list_ = []
+ for el in calc_obj.parse('10^(2+1)'):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, '^', '(', 2.0, '+', 1.0, ')'])
+
+ def test9(self):
+ list_ = []
+ for el in calc_obj.parse('100/3^2'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '/', 3.0, '^', 2.0])
+
+ def test10(self):
+ list_ = []
+ for el in calc_obj.parse('100/3%2^2'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '/', 3.0, '%', 2.0, '^', 2.0])
+
+ # Functions and constants
+ def test11(self):
+ list_ = []
+ for el in calc_obj.parse('pi+e'):
+ list_.append(el)
+ self.assertEqual(list_, ['pi', '+', 'e'])
+
+ def test12(self):
+ list_ = []
+ for el in calc_obj.parse('log(e)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 'e', ')'])
+
+ def test13(self):
+ list_ = []
+ for el in calc_obj.parse('sin(pi/2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'pi', '/', 2.0, ')'])
+
+ def test14(self):
+ list_ = []
+ for el in calc_obj.parse('log10(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log10', '(', 100.0, ')'])
+
+ def test15(self):
+ list_ = []
+ for el in calc_obj.parse('sin(pi/2)*111*6'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'pi', '/', 2.0, ')', '*', 111.0, '*', 6.0])
+
+ def test16(self):
+ list_ = []
+ for el in calc_obj.parse('2*sin(pi/2)'):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, '*', 'sin', '(', 'pi', '/', 2.0, ')'])
+
+ def test17(self):
+ list_ = []
+ for el in calc_obj.parse('abs(-5)'):
+ list_.append(el)
+ self.assertEqual(list_, ['abs', '(', '-', 5.0, ')'])
+
+ def test18(self):
+ list_ = []
+ for el in calc_obj.parse('round(123.456789)'):
+ list_.append(el)
+ self.assertEqual(list_, ['round', '(', 123.456789, ')'])
+
+ # Associative
+ def test19(self):
+ list_ = []
+ for el in calc_obj.parse('102%12%7'):
+ list_.append(el)
+ self.assertEqual(list_, [102.0, '%', 12.0, '%', 7.0])
+
+ def test20(self):
+ list_ = []
+ for el in calc_obj.parse('100/4/3'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '/', 4.0, '/', 3.0])
+
+ def test21(self):
+ list_ = []
+ for el in calc_obj.parse('2^3^4'):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, '^', 3.0, '^', 4.0])
+
+ # Comparison operators
+ def test22(self):
+ list_ = []
+ for el in calc_obj.parse('1+2*3==1+2*3'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '+', 2.0, '*', 3.0, '==', 1.0, '+', 2.0, '*', 3.0])
+
+ def test23(self):
+ list_ = []
+ for el in calc_obj.parse('e^5>=e^5+1'):
+ list_.append(el)
+ self.assertEqual(list_, ['e', '^', 5.0, '>=', 'e', '^', 5.0, '+', 1.0])
+
+ def test24(self):
+ list_ = []
+ for el in calc_obj.parse('1+2*4/3+1!=1+2*4/3+2'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '+', 2.0, '*', 4.0, '/', 3.0, '+', 1.0, '!=', 1.0, '+',
+ 2.0, '*', 4.0, '/', 3.0, '+', 2.0])
+
+ # Common tests
+ def test25(self):
+ list_ = []
+ for el in calc_obj.parse('(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 100.0, ')'])
+
+ def test26(self):
+ list_ = []
+ for el in calc_obj.parse('666'):
+ list_.append(el)
+ self.assertEqual(list_, [666.0])
+
+ def test27(self):
+ list_ = []
+ for el in calc_obj.parse('-.1'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', 0.1])
+
+ def test28(self):
+ list_ = []
+ for el in calc_obj.parse('1/3'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '/', 3.0])
+
+ def test29(self):
+ list_ = []
+ for el in calc_obj.parse('1.0/3.0'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '/', 3.0])
+
+ def test30(self):
+ list_ = []
+ for el in calc_obj.parse('.1 * 2.0^56.0'):
+ list_.append(el)
+ self.assertEqual(list_, [0.1, '*', 2.0, '^', 56.0])
+
+ def test31(self):
+ list_ = []
+ for el in calc_obj.parse('e^34'):
+ list_.append(el)
+ self.assertEqual(list_, ['e', '^', 34.0])
+
+ def test32(self):
+ list_ = []
+ for el in calc_obj.parse('(2.0^(pi/pi+e/e+2.0^0.0))'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/', 'e', '+', 2.0, '^', 0.0, ')', ')'])
+
+ def test33(self):
+ list_ = []
+ for el in calc_obj.parse('(2.0^(pi/pi+e/e+2.0^0.0))^(1.0/3.0)'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/', 'e', '+', 2.0, '^', 0.0,
+ ')', ')', '^', '(', 1.0, '/', 3.0, ')'])
+
+ def test34(self):
+ list_ = []
+ for el in calc_obj.parse('sin(pi/2^1) + log(1*4+2^2+1, 3^2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'pi', '/', 2.0, '^', 1.0, ')', '+', 'log', '(', 1.0, '*', 4.0, '+',
+ 2.0, '^', 2.0, '+', 1.0, ',', 3.0, '^', 2.0, ')'])
+
+ def test35(self):
+ list_ = []
+ for el in calc_obj.parse('10*e^0*log10(.4 -5/ -0.1-10) - -abs(-53/10) + -5'):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, '*', 'e', '^', 0.0, '*', 'log10', '(', 0.4, '-', 5.0, '/', '-', 0.1, '-',
+ 10.0, ')', '-', '-', 'abs', '(', '-', 53.0, '/', 10.0, ')', '+', '-', 5.0])
+
+ def test36(self):
+ list_ = []
+ for el in calc_obj.parse('sin(-cos(-sin(3.0)-cos(-sin(-3.0*5.0)-sin(cos(log10(43.0))))+'
+ 'cos(sin(sin(34.0-2.0^2.0))))--cos(1.0)--cos(0.0)^3.0)'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', '-', 'cos', '(', '-', 'sin', '(', 3.0, ')', '-', 'cos',
+ '(', '-', 'sin', '(', '-', 3.0, '*', 5.0, ')', '-', 'sin', '(', 'cos', '(',
+ 'log10', '(', 43.0, ')', ')', ')', ')', '+', 'cos', '(', 'sin', '(', 'sin', '(',
+ 34.0, '-', 2.0, '^', 2.0, ')', ')', ')', ')', '-', '-', 'cos', '(', 1.0, ')', '-', '-',
+ 'cos', '(', 0.0, ')', '^', 3.0, ')'])
+
+ def test37(self):
+ list_ = []
+ for el in calc_obj.parse('2.0^(2.0^2.0*2.0^2.0)'):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, '^', '(', 2.0, '^', 2.0, '*', 2.0, '^', 2.0, ')'])
+
+ def test38(self):
+ list_ = []
+ for el in calc_obj.parse('sin(e^log(e^e^sin(23.0),45.0) + cos(3.0+log10(e^-e)))'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'e', '^', 'log', '(', 'e', '^', 'e', '^', 'sin', '(', 23.0, ')', ',',
+ 45.0, ')', '+', 'cos', '(', 3.0, '+', 'log10', '(', 'e', '^', '-', 'e', ')', ')', ')'])
+
+ # Error cases
+ def test39(self):
+ list_ = []
+ for el in calc_obj.parse(''):
+ list_.append(el)
+ self.assertEqual(list_, [])
+
+ def test40(self):
+ list_ = []
+ for el in calc_obj.parse('+'):
+ list_.append(el)
+ self.assertEqual(list_, ['+'])
+
+ def test41(self):
+ list_ = []
+ for el in calc_obj.parse('1-'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '-'])
+
+ def test42(self):
+ list_ = []
+ for el in calc_obj.parse('ee'):
+ list_.append(el)
+ self.assertEqual(list_, ['ee'])
+
+ def test43(self):
+ list_ = []
+ for el in calc_obj.parse('==7'):
+ list_.append(el)
+ self.assertEqual(list_, ['==', 7.0])
+
+ def test44(self):
+ list_ = []
+ for el in calc_obj.parse('1 + 2(3 * 4))'):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, '+', 2.0, '(', 3.0, '*', 4.0, ')', ')'])
+
+ def test45(self):
+ list_ = []
+ for el in calc_obj.parse('((1+2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', '(', 1.0, '+', 2.0, ')'])
+
+ def test46(self):
+ list_ = []
+ for el in calc_obj.parse('log100(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log100', '(', 100.0, ')'])
+
+ def test47(self):
+ list_ = []
+ for el in calc_obj.parse('------'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', '-', '-', '-', '-', '-'])
+
+ def test48(self):
+ list_ = []
+ for el in calc_obj.parse('6 * * 6'):
+ list_.append(el)
+ self.assertEqual(list_, [6.0, '*', '*', 6.0])
+
+ def test49(self):
+ list_ = []
+ for el in calc_obj.parse('((((('):
+ list_.append(el)
+ self.assertEqual(list_, ['(', '(', '(', '(', '(', ])
+
+ def test50(self): # how to process commas in pow
+ list_ = []
+ for el in calc_obj.parse('pow(2, 3, 4)'):
+ list_.append(el)
+ self.assertEqual(list_, ['pow', '(', 2.0, ',', 3.0, ',', 4.0, ')'])
+
+ # Self-made cases
+ def test51(self):
+ list_ = []
+ for el in calc_obj.parse('77====77'):
+ list_.append(el)
+ self.assertEqual(list_, [77.0, '==', '==', 77.0])
+
+ def test52(self):
+ list_ = []
+ for el in calc_obj.parse('100/3'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '/', 3.0])
+
+ def test53(self):
+ list_ = []
+ for el in calc_obj.parse('100=3'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '=', 3.0])
+
+ def test54(self):
+ list_ = []
+ for el in calc_obj.parse('100+3'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '+', 3.0])
+
+ def test55(self):
+ list_ = []
+ for el in calc_obj.parse('100//3'):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, '//', 3.0])
+
+ def test56(self):
+ list_ = []
+ for el in calc_obj.parse('sin(sin(1))'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'sin', '(', 1.0, ')', ')'])
+
+ def test57(self):
+ list_ = []
+ for el in calc_obj.parse('sin(sin(1))+1+sin(1)'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'sin', '(', 1.0, ')', ')', '+', 1.0, '+', 'sin', '(', 1.0, ')'])
+
+ def test58(self):
+ list_ = []
+ for el in calc_obj.parse('log100l(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log100l', '(', 100.0, ')'])
+
+ def test59(self):
+ list_ = []
+ for el in calc_obj.parse('log100+(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log100', '+', '(', 100.0, ')'])
+
+ def test60(self):
+ list_ = []
+ for el in calc_obj.parse('.+1'):
+ list_.append(el)
+ self.assertEqual(list_, ['.', '+', 1.0, ])
+
+ # logarithms
+ def test61(self):
+ list_ = []
+ for el in calc_obj.parse('log(8,2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 8.0, ',', 2.0, ')'])
+
+ def test62(self):
+ list_ = []
+ for el in calc_obj.parse('log(2.7)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 2.7, ')'])
+
+ def test63(self):
+ list_ = []
+ for el in calc_obj.parse('(log(8,2)-1)-2'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 'log', '(', 8.0, ',', 2.0, ')', '-', 1.0, ')', '-', 2.0])
+
+ def test64(self):
+ list_ = []
+ for el in calc_obj.parse('-log(8,2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', 'log', '(', 8.0, ',', 2.0, ')'])
+
+ def test65(self):
+ list_ = []
+ for el in calc_obj.parse('log(8,2)-1'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 8.0, ',', 2.0, ')', '-', 1.0])
+
+ def test66(self):
+ list_ = []
+ for el in calc_obj.parse('log(8,2)*log(16,2)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 8.0, ',', 2.0, ')', '*', 'log', '(', 16.0, ',', 2.0, ')'])
+
+ def test67(self):
+ list_ = []
+ for el in calc_obj.parse('sin(log(8,2)*log(16,2))'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'log', '(', 8.0, ',', 2.0, ')', '*', 'log', '(', 16.0, ',', 2.0, ')', ')'])
+
+ def test68(self):
+ list_ = []
+ for el in calc_obj.parse('log(8+20-1,2+1)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 8.0, '+', 20.0, '-', 1.0, ',', 2.0, '+', 1.0, ')'])
+
+ def test69(self):
+ list_ = []
+ for el in calc_obj.parse('log10(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log10', '(', 100.0, ')'])
+
+ def test70(self):
+ list_ = []
+ for el in calc_obj.parse('log(100,10)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 100.0, ',', 10.0, ')'])
+
+ def test71(self):
+ list_ = []
+ for el in calc_obj.parse('(log10(100)-1)-2'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 'log10', '(', 100.0, ')', '-', 1.0, ')', '-', 2.0])
+
+ def test72(self):
+ list_ = []
+ for el in calc_obj.parse('-log10(100)'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', 'log10', '(', 100.0, ')'])
+
+ def test73(self):
+ list_ = []
+ for el in calc_obj.parse('log10(100)-1'):
+ list_.append(el)
+ self.assertEqual(list_, ['log10', '(', 100.0, ')', '-', 1.0])
+
+ def test74(self):
+ list_ = []
+ for el in calc_obj.parse('log10(100)*log10(1000)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0, ')'])
+
+ def test75(self):
+ list_ = []
+ for el in calc_obj.parse('sin(log10(100)*log10(1000))'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0, ')', ')'])
+
+ def test76(self):
+ list_ = []
+ for el in calc_obj.parse('log10(800/2/4)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log10', '(', 800.0, '/', 2.0, '/', 4.0, ')'])
+
+ # pow
+ def test77(self):
+ list_ = []
+ for el in calc_obj.parse('pow(2,4)'):
+ list_.append(el)
+ self.assertEqual(list_, ['pow', '(', 2.0, ',', 4.0, ')'])
+
+ def test78(self):
+ list_ = []
+ for el in calc_obj.parse('log(pow(10,2),10)'):
+ list_.append(el)
+ self.assertEqual(list_, ['log', '(', 'pow', '(', 10.0, ',', 2.0, ')', ',', 10.0, ')'])
+
+ def test79(self):
+ list_ = []
+ for el in calc_obj.parse('(pow(2,4)-1)-2'):
+ list_.append(el)
+ self.assertEqual(list_, ['(', 'pow', '(', 2.0, ',', 4.0, ')', '-', 1.0, ')', '-', 2.0])
+
+ def test80(self):
+ list_ = []
+ for el in calc_obj.parse('-pow(2,4)'):
+ list_.append(el)
+ self.assertEqual(list_, ['-', 'pow', '(', 2.0, ',', 4.0, ')'])
+
+ def test81(self):
+ list_ = []
+ for el in calc_obj.parse('pow(2,4)-1'):
+ list_.append(el)
+ self.assertEqual(list_, ['pow', '(', 2.0, ',', 4.0, ')', '-', 1.0])
+
+ def test82(self):
+ list_ = []
+ for el in calc_obj.parse('pow(2,4)*pow(2,3)'):
+ list_.append(el)
+ self.assertEqual(list_, ['pow', '(', 2.0, ',', 4.0, ')', '*', 'pow', '(', 2.0, ',', 3.0, ')'])
+
+ def test83(self):
+ list_ = []
+ for el in calc_obj.parse('sin(pow(2,4)*pow(2,3))'):
+ list_.append(el)
+ self.assertEqual(list_, ['sin', '(', 'pow', '(', 2.0, ',', 4.0, ')', '*', 'pow', '(', 2.0, ',', 3.0, ')', ')'])
+
+ def test84(self):
+ list_ = []
+ for el in calc_obj.parse('pow(2.0^(2.0^2.0*2.0^2.0),sin(log10(100)*log10(1000)))'):
+ list_.append(el)
+ self.assertEqual(list_, ['pow', '(', 2.0, '^', '(', 2.0, '^', 2.0, '*', 2.0, '^', 2.0, ')', ',', 'sin', '(',
+ 'log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0, ')', ')', ')'])
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/final_task/unittests/unittests_prevalidation.py b/final_task/unittests/unittests_prevalidation.py
new file mode 100644
index 00000000..35f9bfe3
--- /dev/null
+++ b/final_task/unittests/unittests_prevalidation.py
@@ -0,0 +1,97 @@
+import unittest
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+
+calc_obj = PyCalcProcessing('1')
+
+
+class TestParsingNegativeCases(unittest.TestCase):
+ def test1(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1+&6.0'))
+
+ def test86(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1+6.0&'))
+
+ def test87(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('_5+6'))
+
+ def test88(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('5_+6'))
+
+ def test89(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1>=@'))
+
+ def test90(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1@>=9'))
+
+ def test91(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('-2+(#+1)'))
+
+ def test92(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('abs(@)'))
+
+ def test93(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('round(@)'))
+
+ def test94(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('sin(5+@)'))
+
+ def test95(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('sin(@+5)'))
+
+ def test96(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('(5+@)/7'))
+
+ def test97(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1+#+6'))
+
+ def test98(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1+#8+6'))
+
+ # Number with more than one delimiter
+ def test99(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1..5'))
+
+ def test100(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('-1..5'))
+
+ def test101(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1..5+3..7'))
+
+ def test102(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1..5+3'))
+
+ def test103(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('3+1..5'))
+
+ def test104(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1+1..5-4'))
+
+ def test105(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('sin(1..5)'))
+
+ def test106(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('(1..5+3)/2'))
+
+ def test107(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('round(1..5)'))
+
+ def test108(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('abs(-1..5)'))
+
+ def test109(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate('1>=1..5'))
+
+ def test110(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate(''))
+
+ def test111(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate(None))
+
+ def test112(self):
+ self.assertEqual(True, lambda: calc_obj.pre_validate(18))
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/final_task/unittests/unittests_sort_to_polish_function.py b/final_task/unittests/unittests_sort_to_polish_function.py
new file mode 100644
index 00000000..6bb3cdd3
--- /dev/null
+++ b/final_task/unittests/unittests_sort_to_polish_function.py
@@ -0,0 +1,524 @@
+import unittest
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+calc_obj = PyCalcProcessing('1')
+
+
+class TestSorting(unittest.TestCase):
+
+ # Unary operators
+ def test1(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 13.0]):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 13.0, '-'])
+
+ def test2(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([6.0, '-', '(', '-', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [6.0, 0.0, 13.0, '-', '-'])
+
+ def test3(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '-', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 1.0, '-'])
+
+ def test4(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 1.0, '-'])
+
+ # Operation priority
+ def test5(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '+', 2.0, '*', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 2.0, 2.0, '*', '+'])
+
+ def test6(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '+', '(', 2.0, '+', 3.0, '*', 2.0, ')', '*', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 2.0, 3.0, 2.0, '*', '+', 3.0, '*', '+'])
+
+ def test7(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([10.0, '*', '(', 2.0, '+', 1.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, 2.0, 1.0, '+', '*'])
+
+ def test8(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([10.0, '^', '(', 2.0, '+', 1.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, 2.0, 1.0, '+', '^'])
+
+ def test9(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '/', 3.0, '^', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 3.0, 2.0, '^', '/'])
+
+ def test10(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '/', 3.0, '%', 2.0, '^', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 3.0, '/', 2.0, 2.0, '^', '%'])
+
+ # Functions and constants
+ def test11(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['pi', '+', 'e']):
+ list_.append(el)
+ self.assertEqual(list_, ['pi', 'e', '+'])
+
+ def test12(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 'e', ')']):
+ list_.append(el)
+ self.assertEqual(list_, ['e', 'log'])
+
+ def test13(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'pi', '/', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, ['pi', 2.0, '/', 'sin'])
+
+ def test14(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log10', '(', 100.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10'])
+
+ def test15(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'pi', '/', 2.0, ')', '*', 111.0, '*', 6.0]):
+ list_.append(el)
+ self.assertEqual(list_, ['pi', 2.0, '/', 'sin', 111.0, '*', 6.0, '*'])
+
+ def test16(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([2.0, '*', 'sin', '(', 'pi', '/', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 'pi', 2.0, '/', 'sin', '*'])
+
+ def test17(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['abs', '(', '-', 5.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 5.0, '-', 'abs'])
+
+ def test18(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['round', '(', 123.456789, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [123.456789, 'round'])
+
+ # Associative
+ def test19(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([102.0, '%', 12.0, '%', 7.0]):
+ list_.append(el)
+ self.assertEqual(list_, [102.0, 12.0, '%', 7.0, '%'])
+
+ def test20(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '/', 4.0, '/', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 4.0, '/', 3.0, '/'])
+
+ def test21(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([2.0, '^', 3.0, '^', 4.0]):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 3.0, 4.0, '^', '^'])
+
+ # Comparison operators
+ def test22(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '+', 2.0, '*', 3.0, '==', 1.0, '+', 2.0, '*', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 2.0, 3.0, '*', '+', 1.0, 2.0, 3.0, '*', '+', '=='])
+
+ def test23(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['e', '^', 5.0, '>=', 'e', '^', 5.0, '+', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, ['e', 5.0, '^', 'e', 5.0, '^', 1.0, '+', '>='])
+
+ def test24(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '+', 2.0, '*', 4.0, '/', 3.0, '+', 1.0, '!=',
+ 1.0, '+', 2.0, '*', 4.0, '/', 3.0, '+', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 2.0, 4.0, '*', 3.0, '/', '+', 1.0, '+', 1.0,
+ 2.0, 4.0, '*', 3.0, '/', '+', 2.0, '+', '!='])
+
+ # Common tests
+ def test25(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 100.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0])
+
+ def test26(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([666.0]):
+ list_.append(el)
+ self.assertEqual(list_, [666.0])
+
+ def test27(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 0.1]):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 0.1, '-'])
+
+ def test28(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '/', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 3.0, '/'])
+
+ def test29(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '/', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 3.0, '/'])
+
+ def test30(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([0.1, '*', 2.0, '^', 56.0]):
+ list_.append(el)
+ self.assertEqual(list_, [0.1, 2.0, 56.0, '^', '*'])
+
+ def test31(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['e', '^', 34.0]):
+ list_.append(el)
+ self.assertEqual(list_, ['e', 34.0, '^'])
+
+ def test32(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/',
+ 'e', '+', 2.0, '^', 0.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 'pi', 'pi', '/', 'e', 'e', '/', '+', 2.0, 0.0, '^', '+', '^'])
+
+ def test33(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/', 'e', '+', 2.0,
+ '^', 0.0, ')', ')', '^', '(', 1.0, '/', 3.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 'pi', 'pi', '/', 'e', 'e', '/', '+', 2.0, 0.0, '^', '+',
+ '^', 1.0, 3.0, '/', '^'])
+
+ def test34(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 1.0, '*', 4.0, '+', 2.0, '^', 2.0, '+', 1.0,
+ ',', 3.0, '^', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 4.0, '*', 2.0, 2.0, '^', '+', 1.0, '+', 3.0, 2.0, '^', 'log'])
+
+ def test35(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([10.0, '*', 'e', '^', 0.0, '*', 'log10', '(', 0.4, '-', 5.0, '/', '-', 0.1,
+ '-', 10.0, ')', '+', 'abs', '(', '-', 53.0, '/', 10.0, ')', '-', 5.0]):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, 'e', 0.0, '^', '*', 0.4, 5.0, 0.0, 0.1, '-', '/', '-', 10.0, '-', 'log10', '*',
+ 0.0, 53.0, 10.0, '/', '-', 'abs', '+', 5.0, '-'])
+
+ def test36(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', '-', 'cos', '(', '-', 'sin', '(', 3.0, ')', '-', 'cos', '(', '-',
+ 'sin', '(', '-', 3.0, '*', 5.0, ')', '-', 'sin', '(', 'cos', '(', 'log10',
+ '(', 43.0, ')', ')', ')', ')', '+', 'cos', '(', 'sin', '(', 'sin', '(', 34.0,
+ '-', 2.0, '^', 2.0, ')', ')', ')', ')', '+', 'cos', '(', 1.0, ')', '+',
+ 'cos', '(', 0.0, ')', '^', 3.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 0.0, 3.0, 'sin', '-', 0.0, 0.0, 3.0, 5.0, '*', '-', 'sin', '-', 43.0, 'log10',
+ 'cos', 'sin', '-', 'cos', '-', 34.0, 2.0, 2.0, '^', '-', 'sin', 'sin', 'cos', '+',
+ 'cos', '-', 1.0, 'cos', '+', 0.0, 3.0, '^', 'cos', '+', 'sin'])
+
+ def test37(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([2.0, '^', '(', 2.0, '^', 2.0, '*', 2.0, '^', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 2.0, 2.0, '^', 2.0, 2.0, '^', '*', '^'])
+
+ def test38(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'e', '^', 'log', '(', 'e', '^', 'e', '^', 'sin', '(', 23.0, ')',
+ ',', 45.0, ')', '+', 'cos', '(', 3.0, '+', 'log10', '(', 'e', '^', '-', 'e',
+ ')', ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, ['e', 'e', 'e', 23.0, 'sin', '^', '^', 45.0, 'log', '^', 3.0, 'e', 0.0,
+ 'e', '-', '^', 'log10', '+', 'cos', '+', 'sin'])
+
+ # Self-made cases
+ def test52(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '/', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 3.0, '/'])
+
+ def test54(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '+', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 3.0, '+'])
+
+ def test55(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([100.0, '//', 3.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 3.0, '//'])
+
+ def test56(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'sin', '(', 1.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 'sin', 'sin'])
+
+ def test57(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'sin', '(', 1.0, ')', ')', '+', 1.0, '+', 'sin', '(', 1.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 'sin', 'sin', 1.0, '+', 1.0, 'sin', '+'])
+
+ def test58(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['abs', '(', '-', 3.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 3.0, '-', 'abs'])
+
+ def test59(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['round', '(', 3.56393, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [3.56393, 'round'])
+
+ def test60(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['abs', '(', '-', 'round', '(', 3.56393, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 3.56393, 'round', '-', 'abs'])
+
+ # logarithms
+ def test61(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 8.0, ',', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 2.0, 'log'])
+
+ def test62(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 2.7, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.7, 'log'])
+
+ def test63(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 'log', '(', 8.0, ',', 2.0, ')', '-', 1.0, ')', '-', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 2.0, 'log', 1.0, '-', 2.0, '-'])
+
+ def test64(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 'log', '(', 8.0, ',', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 8.0, 2.0, 'log', '-'])
+
+ def test65(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 8.0, ',', 2.0, ')', '-', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 2.0, 'log', 1.0, '-'])
+
+ def test66(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 8.0, ',', 2.0, ')', '*', 'log', '(', 16.0, ',', 2.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 2.0, 'log', 16.0, 2.0, 'log', '*'])
+
+ def test67(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'log', '(', 8.0, ',', 2.0, ')', '*', 'log', '(', 16.0, ',', 2.0,
+ ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 2.0, 'log', 16.0, 2.0, 'log', '*', 'sin'])
+
+ def test68(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 8.0, '+', 20.0, '-', 1.0, ',', 2.0, '+', 1.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [8.0, 20.0, '+', 1.0, '-', 2.0, 1.0, '+', 'log'])
+
+ def test69(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log10', '(', 100.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10'])
+
+ def test70(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 100.0, ',', 10.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 10.0, 'log'])
+
+ def test71(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 'log10', '(', 100.0, ')', '-', 1.0, ')', '-', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10', 1.0, '-', 2.0, '-'])
+
+ def test72(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 'log10', '(', 100.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 100.0, 'log10', '-'])
+
+ def test73(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log10', '(', 100.0, ')', '-', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10', 1.0, '-'])
+
+ def test74(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10', 1000.0, 'log10', '*'])
+
+ def test75(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [100.0, 'log10', 1000.0, 'log10', '*', 'sin'])
+
+ def test76(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log10', '(', 800.0, '/', 2.0, '/', 4.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [800.0, 2.0, '/', 4.0, '/', 'log10'])
+
+ # pow
+ def test77(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['pow', '(', 2.0, ',', 4.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 4.0, 'pow'])
+
+ def test78(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['log', '(', 'pow', '(', 10.0, ',', 2.0, ')', ',', 10.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [10.0, 2.0, 'pow', 10.0, 'log'])
+
+ def test79(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 'pow', '(', 2.0, ',', 4.0, ')', '-', 1.0, ')', '-', 2.0]):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 4.0, 'pow', 1.0, '-', 2.0, '-'])
+
+ def test80(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 'pow', '(', 2.0, ',', 4.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 2.0, 4.0, 'pow', '-'])
+
+ def test81(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['pow', '(', 2.0, ',', 4.0, ')', '-', 1.0]):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 4.0, 'pow', 1.0, '-'])
+
+ def test82(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['pow', '(', 2.0, ',', 4.0, ')', '*', 'pow', '(', 2.0, ',', 3.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 4.0, 'pow', 2.0, 3.0, 'pow', '*'])
+
+ def test83(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['sin', '(', 'pow', '(', 2.0, ',', 4.0, ')', '*',
+ 'pow', '(', 2.0, ',', 3.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 4.0, 'pow', 2.0, 3.0, 'pow', '*', 'sin'])
+
+ def test84(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['pow', '(', 2.0, '^', '(', 2.0, '^', 2.0, '*', 2.0, '^', 2.0, ')', ',',
+ 'sin', '(', 'log10', '(', 100.0, ')', '*', 'log10', '(', 1000.0,
+ ')', ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [2.0, 2.0, 2.0, '^', 2.0, 2.0, '^', '*', '^', 100.0, 'log10', 1000.0, 'log10', '*',
+ 'sin', 'pow'])
+
+ # unary_operations
+ def test85(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([13.0]):
+ list_.append(el)
+ self.assertEqual(list_, [13.0])
+
+ def test86(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', '(', '-', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 0.0, 13.0, '-', '-'])
+
+ def test87(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', '(', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 13.0, '-'])
+
+ def test88(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '*', '-', 13.0]):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 0.0, 13.0, '-', '*'])
+
+ def test89(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '*', '(', '-', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 0.0, 13.0, '-', '*'])
+
+ def tes90(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish([1.0, '*', '(', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 13.0, '*'])
+
+ def test91(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', 1.0, '+', 13.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0, 13.0, '+'])
+
+ def test92(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', 1.0, '-', '(', '-', 1.0, ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 1.0, '-', 0.0, 1.0, '-', '-'])
+
+ def test93(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['(', '(', 1.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [1.0])
+
+ def test94(self):
+ list_ = []
+ for el in calc_obj.sort_to_polish(['-', '(', '-', '(', '-', 1.0, ')', ')']):
+ list_.append(el)
+ self.assertEqual(list_, [0.0, 0.0, 0.0, 1.0, '-', '-', '-'])
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/final_task/unittests/unittests_validation.py b/final_task/unittests/unittests_validation.py
new file mode 100644
index 00000000..7e8d65b9
--- /dev/null
+++ b/final_task/unittests/unittests_validation.py
@@ -0,0 +1,352 @@
+import unittest
+
+from final_task.pycalc_proc import PyCalcProcessing
+
+calc_obj = PyCalcProcessing('1')
+
+
+class ExpectedFailureTestCase(unittest.TestCase):
+ # Error cases
+ def test1(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['+', '+']))
+
+ def test2(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['+']))
+
+ def test3(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([1.0, '-']))
+
+ def test4(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['ee']))
+
+ def test5(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['==', 7.0]))
+
+ def test6(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([1.0, '+', 2.0, '(', 3.0, '*', 4.0, ')', ')']))
+
+ def test7(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '(', 1.0, '+', 2.0, ')']))
+
+ def test8(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ')']))
+
+ def test9(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['log10', 0.0, '(', 100.0, ')']))
+
+ def test10(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['-', '-', '-', '-', '-', '-']))
+
+ def test11(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ')']))
+
+ def test12(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([6.0, '*', '*', 6.0]))
+
+ def test13(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ')']))
+
+ def test14(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '(', '(', '(', '(', ]))
+
+ def test15(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([77.0, '==', '==', 77.0]))
+
+ def test16(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['_', '+', 'son']))
+
+ def test17(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')', '+', 2.0]))
+
+ def test18(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ',', 77.0, '-', 4.0, ')', '+', 2.0]))
+
+ def test19(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '//', 77.0, '-', 4.0, ')', '+', 2.0]))
+
+ def test20(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', 1.0, '+', 5.0, ')', '(',
+ 1.0, '+', 5.0, ')']))
+
+ def test21(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')', '.', 2.0]))
+
+ def test22(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ',', 77.0, '-', 4.0, ')', ',', 2.0]))
+
+ def test23(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '//', 77.0, '-', 4.0, ')',
+ 'sin', '(', 2.0, ')']))
+
+ def test24(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')', 2.0, '+', 1.0]))
+
+ def test25(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', ',', 77.0, '-', 4.0, ')', 'e']))
+
+ def test26(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '//', 77.0, '-', 4.0,
+ ')', 'sin', '(', 2.0, ')']))
+
+ def test27(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')',
+ '.', '(', 2.0, '+', '1']))
+
+ def test28(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, '.', '.', ')']))
+
+ def test29(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')',
+ '.', '(', 2.0, '+', '1']))
+
+ def test30(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')',
+ '.', ',', 2.0, '+', '1']))
+
+ def test31(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')',
+ '.', '-', 2.0, '+', '1']))
+
+ def test32(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')',
+ '.', 'sin', '(', 2.0, ')']))
+
+ def test33(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['(', '.', 77.0, '-', 4.0, ')', '.', 'e']))
+
+ def test34(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['-', ')', 4.0]))
+
+ def test35(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['-', '.', 4.0]))
+
+ def test36(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['-', ',', 4.0]))
+
+ def test37(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['-', '//', 4.0]))
+
+ def test38(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([26.0, '//', ')', 4.0]))
+
+ def test39(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([26.0, '//', '.', 4.0]))
+
+ def test40(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([26.0, '//', ',', 4.0]))
+
+ def test41(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([26.0, '//', '%', 4.0]))
+
+ def test42(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', ')', 4.0, ')']))
+
+ def test43(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', '.', 4.0, ')']))
+
+ def test44(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', ',', 4.0, ')']))
+
+ def test45(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', '-', 4.0, ')']))
+
+ def test46(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', '//', 4.0, ')']))
+
+ def test47(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', 'cos', 4.0, ')']))
+
+ def test48(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', 4.0, ')']))
+
+ def test49(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['cos', 'e', 4.0, ')']))
+
+ def test50(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([4.0, '(', '+', 5.0, ')']))
+
+ def test51(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([4.0, '.', '+', 5.0]))
+
+ def test52(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([4.0, 'sin', '(', 5.0, ')']))
+
+ def test53(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([4.0, 3.0, '+', 5.0]))
+
+ def test54(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([4.0, 'e', '+', 5.0, ')']))
+
+ def test55(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['e', '(', '+', 'pi']))
+
+ def test56(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['e', '.', '+', 'pi']))
+
+ def test57(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['e', 'sin', '(', 3.0, ')']))
+
+ def test58(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['e', 3.0, '+', 'pi']))
+
+ # matched parentheses
+ def test59(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([15.0, '*', '(', 25.0, '+', 1.0]))
+
+ def test60(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([15.0, '*', 25.0, '+', 1.0, ')']))
+
+ def test61(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([15.0, '*', ')', 25.0, '+', 1.0, ')']))
+
+ def test62(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([15.0, '*', 25.0, '+', 1.0, '(', ')']))
+
+ def test63(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list([15.0, '*', 25.0, '+', '(', 1.0,
+ '+', ')', 1.0, ')']))
+
+ def test64(self):
+ self.assertEqual(True, lambda: calc_obj.validate_parsed_list(['abs']))
+
+
+class ExpectedSuccessTestCase(unittest.TestCase):
+ def test1(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['-', 13.0]))
+
+ def test2(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([6.0, '-', '(', '-', 13.0, ')']))
+
+ def test3(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '-', '-', '-', 1.0]))
+
+ def test4(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['-', '+', '-', '-', '-', '+', '-', 1.0]))
+
+ def test5(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '+', 2.0, '*', 2.0]))
+
+ def test6(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '+', '(', 2.0, '+', 3.0, '*', 2.0, ')', '*', 3.0]))
+
+ def test7(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([10.0, '*', '(', 2.0, '+', 1.0, ')']))
+
+ def test8(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([10.0, '^', '(', 2.0, '+', 1.0, ')']))
+
+ def test9(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([100.0, '/', 3.0, '^', 2.0]))
+
+ def test10(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([100.0, '/', 3.0, '%', 2.0, '^', 2.0]))
+
+ def test11(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['pi', '+', 'e']))
+
+ def test12(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['log', '(', 'e', ')']))
+
+ def test13(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['sin', '(', 'pi', '/', 2.0, ')']))
+
+ def test14(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['log10', '(', 100.0, ')']))
+
+ def test15(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['sin', '(', 'pi', '/', 2.0, ')', '*', 111.0, '*', 6.0]))
+
+ def test16(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([2.0, '*', 'sin', '(', 'pi', '/', 2.0, ')']))
+
+ def test17(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['abs', '(', '-', 5.0, ')']))
+
+ def test18(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['round', '(', 123.456789, ')']))
+
+ def test19(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([102.0, '%', 12.0, '%', 7.0]))
+
+ def test20(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([100.0, '/', 4.0, '/', 3.0]))
+
+ def test21(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([2.0, '^', 3.0, '^', 4.0]))
+
+ def test22(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '+', 2.0, '*', 3.0, '==', 1.0, '+', 2.0, '*', 3.0]))
+
+ def test23(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['e', '^', 5.0, '>=', 'e', '^', 5.0, '+', 1.0]))
+
+ def test24(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '+', 2.0, '*', 4.0, '/', 3.0, '+', 1.0, '!=', 1.0,
+ '+', 2.0, '*', 4.0, '/', 3.0, '+', 2.0]))
+
+ def test25(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['(', 100.0, ')']))
+
+ def test26(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([666.0]))
+
+ def test27(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['-', 0.1]))
+
+ def test28(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '/', 3.0]))
+
+ def test29(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([0.1, '*', 2.0, '^', 56.0]))
+
+ def test30(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['e', '^', 34.0]))
+
+ def test31(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/', 'e',
+ '+', 2.0, '^', 0.0, ')', ')']))
+
+ def test32(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['(', 2.0, '^', '(', 'pi', '/', 'pi', '+', 'e', '/', 'e',
+ '+', 2.0, '^', 0.0, ')', ')', '^', '(', 1.0, '/',
+ 3.0, ')']))
+
+ def test33(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([10.0, '*', 'e', '^', 0.0, '*', 'log10', '(', 0.4, '-',
+ 5.0, '/', '-', 0.1, '-', 10.0, ')', '-', '-', 'abs', '(',
+ '-', 53.0, '/', 10.0, ')', '+', '-', 5.0]))
+
+ def test34(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['sin', '(', '-', 'cos', '(', '-', 'sin', '(', 3.0, ')',
+ '-', 'cos', '(', '-', 'sin', '(', '-', 3.0, '*', 5.0,
+ ')', '-', 'sin', '(', 'cos', '(', 'log10', '(', 43.0,
+ ')', ')', ')', ')', '+', 'cos', '(', 'sin', '(', 'sin',
+ '(', 34.0, '-', 2.0, '^', 2.0, ')', ')', ')', ')', '-',
+ '-', 'cos', '(', 1.0, ')', '-', '-', 'cos', '(', 0.0,
+ ')', '^', 3.0, ')']))
+
+ def test35(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([2.0, '^', '(', 2.0, '^', 2.0, '*', 2.0, '^', 2.0, ')']))
+
+ def test36(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['sin', '(', 'e', '^', 'log', '(', 'e', '^', 'e', '^',
+ 'sin', '(', 23.0, ')', ',', 45.0, ')', '+', 'cos', '(',
+ 3.0, '+', 'log10', '(', 'e', '^', '-', 'e', ')', ')',
+ ')']))
+
+ def test37(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list([1.0, '*', '-', 13.0]))
+
+ def test38(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['log', '(', 1.0, ',', '-', 13.0, ')']))
+
+ def test39(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['log', '(', 1.0, ',', '(', '-', 13.0, ')', ')']))
+
+ # incorrect number of arguments processing in calc
+ def test40(self):
+ self.assertEqual(False, calc_obj.validate_parsed_list(['pow', '(', 1.0, ')']))
+
+
+if __name__ == '__main__':
+ unittest.main()