def test_emptyexpr(): with pytest.raises(ValueError): postfix('')
def test_emptystack(): with pytest.raises(ValueError): postfix('1 2 + /')
def test_trig(): assert postfix('pi cos') == -1 assert postfix('pi 2 / sin') == 1 assert 0.99 < postfix('pi 4 / tan') < 1.01
def test_multiple(): assert postfix('48 8 / 3 + 7 *') == 63
def test_binops(): assert postfix('1 7 +') == 8 assert postfix('7 3 -') == 4 assert postfix('7 3 *') == 21 assert postfix('48 8 /') == 6 assert postfix('2 3 **') == 8
def test_unops(): assert postfix('pi deg') == 180 assert postfix('4 sqrt') == 2 assert postfix('90 rad 2 *') == pi assert postfix('100 log') == 2
def test_medium_int(self): self.assertEqual(postfix_evaluation(postfix("( 5 + 5 * 3 ) / 12 + ( 2 / 1 )")), 3.67)
import postfix as postfix exp = input("Enter the Expression:") post = postfix.postfix(exp) code = [] stk = [] t = 0 for i in post: if i.islower(): stk.append(i) elif i == '+' or i == '-' or i == '*' or i == '/': b = stk.pop() a = stk.pop() code.append('t' + str(t) + '=' + a + i + b) stk.append('t' + str(t)) t += 1 b = stk.pop() a = stk.pop() code.append(a + "=" + b) print("\n===============INTERMEDIATE CODE==============\n") for i in code: print('\t\t', i) print("==============================================")
def test_simple_int(self): self.assertEqual(postfix_evaluation(postfix("5 + 5")), 10.00)
def test_postfix(self): given = "352+*9-" expect = 12 actual = postfix(given) self.assertEqual(expect, actual)
return pow(op1, op2) else: return op1 - op2 def postfix_evaluation(post_expr): my_stack = Stack() post_expr = post_expr.split() for token in post_expr: if checker(token): my_stack.push(token) elif token == '#': my_stack.push(sqrt(num(my_stack.pop()))) elif token == "|": my_stack.push(abs(num(my_stack.pop()))) else: op2 = num(my_stack.pop()) op1 = num(my_stack.pop()) result = evaluation(op1, op2, token) my_stack.push(result) return "{:.2f}".format(my_stack.pop()) infix_expression = input('Приклад:\n') postfix_expresion = postfix(infix_expression) postfix_result = postfix_evaluation(postfix_expresion) print("Приклад записаний інфіксом = {}".format(infix_expression)) print("Приклад записаний постфіксом = {}".format(postfix_expresion)) print("Результат: {}".format(postfix_result))
''' пароль пользователя для подключения к ldap-каталогу ''' ad_password = conf.get_ldap_password() ''' дерево поиска ldap ''' ad_search_tree = conf.get_ldap_search_tree() ''' группы ldap-каталога, имеющие доступ к отправке smtp ''' ad_smtp_groups = json.loads(conf.get_smtp_ldap_groups()) ''' путь к файлу generic ''' out_generic = conf.get_generic_path() ''' путь к файлу relayhost_map ''' out_relayhost = conf.get_relayhost_path() ''' путь к файлу saslpass ''' out_saslpass = conf.get_saslpass_path() ''' инициализация классов для работы с LDAP и Postfix ''' ldap = ad(ad_server, ad_user, ad_password) smtp = postfix(out_generic, out_relayhost, out_saslpass) """ обработка групп конфигуграций smtp """ for item in ad_smtp_groups: section = ad_smtp_groups[item] ''' получение группы пользователей ldap из файла конфигурации ''' ad_group = conf.get_ldap_group(section) ''' получение smtp-имени пользователя из файла конфигурации ''' smtp_user = conf.get_smtp_user(section) ''' получение smtp-пароля пользователя из файла конфигурации ''' smtp_password = conf.get_smtp_password(section) ''' получение адреса smtp-сервера из файла конфигурации ''' smtp_server = conf.get_smtp_server(section) ''' получение порта smtp-сервера из файла конфигурации '''
def test_postix(self): test_cases = ["2+7*5", "3*3/(7+1)", "5+(6-2)*9+3^(7-1)"] solutions = ["275*+", "33*71+/", "562-9*+371-^+"] for index, case in enumerate(test_cases): print(postfix(case)) self.assertEqual(postfix(case), solutions[index])