Esempio n. 1
0
def test_topostfix():
    case = (
       ("8-(3+2*6)/5+4", "8 3 2 6 * + 5 / - 4 +"),
       ("((5+7)/3*7-(3*2))+(7-3)*3+2*5+4*5+1*6+1*5", "5 7 + 3 / 7 * 3 2 * - 7 3 - 3 * + 2 5 * + 4 5 * + 1 6 * + 1 5 * +"),
       ("1*((2+3) /2) ^5", "1 2 3 + 2 / 5 ** *"),
       ("-1+((2+3)*4/5)", "1 - 2 3 + 4 * 5 / +"),
       ("-1+-5", "1 - 5 - +"),
       ("pow(3,2)+ sin(45)", "3 2 , pow 45 sin +"),
       ("-$a+$b*(-$c+$d)+$e", "_a - _b _c - _d + * + _e +"),
       ("pOw(1*(2+3), 6+5)", "1 2 3 + * 6 5 + , pow"),
       ("-1+5*-6", "1 - 5 6 - * +"),
       ("Sum([1+1,5+6*7,POW (3,2)])", "1 1 + 5 6 7 * + , 3 2 , pow , sum"),
       ("5/ 4mod sin(1)+SUm([1,2])^3.5* 2-4", "5 4 1 sin % / 1 2 , sum 3.5 ** 2 * + 4 -"),
       ("4", "4"),
       ("-sin(45)", "45 sin -"),
       ("-+-+sin(45)", "45 sin + - + -"),
       ("$var", "_var"),
       ("-(+5+6)", "5 + 6 + -"),
       ("$vAr", "_var"),
    )

    for c, r in case:
        exp = Convertor.preprocessing(c)
        gtk = Convertor.tokenize(exp)
        rr = Convertor.topostfix(gtk)
        assert " ".join(map(str, rr)) == r
Esempio n. 2
0
def test_preprocessing():
    case = (
        ("1+1", "1+1"),
        ("1 + 1 ", "1 + 1"),
        (" 1 +1", "1 +1"),
        ("1 pOw $e", "1 pow _e"),
    )
    for c, r in case:
        assert Convertor.preprocessing(c) == r