pygorithm/test/test_stack.py

58 lines
1.2 KiB
Python

from stack.parentheses import par_match
from stack.number_conversion import decimal_to_any
from stack.infix_conversion import infix_to_prefix, infix_to_postfix
def test_par_match1():
parentheses = '((()))(()()'
assert not par_match(parentheses)
def test_par_match2():
parentheses = '((()))(())'
assert par_match(parentheses)
def test_par_match3():
parentheses = '(((5+3)))*((4-2))'
assert par_match(parentheses)
def test_to_binary1():
num = 5
assert decimal_to_any(num, 2) == '101'
def test_to_binary2():
num = 10
assert decimal_to_any(num, 2) == '1010'
def test_infix_to_prefix():
infix = 'a+b*c'
assert infix_to_prefix(infix) == '+a*bc'
def test_infix_to_prefix_with_parentheses1():
infix = '(a+b)*c'
assert infix_to_prefix(infix) == '*+abc'
def test_infix_to_prefix_with_parentheses2():
infix = '(a+b)*(c-d)'
assert infix_to_prefix(infix) == '*+ab-cd'
def test_infix_to_postfix():
infix = 'a+b*c'
assert infix_to_postfix(infix) == 'abc*+'
def test_infix_to_postfix_with_parentheses1():
infix = '(a+b)*c'
assert infix_to_postfix(infix) == 'ab+c*'
def test_infix_to_postfix_with_parentheses2():
infix = '(a+b)/(c-d)'
assert infix_to_postfix(infix) == 'ab+cd-/'