import unittest from src.parser import Parser from src.node import ExpressionNode as N, ExpressionLeaf as L from tests.parser import run_expressions class TestB1Ch10(unittest.TestCase): def test_diagnostic_test(self): run_expressions(Parser, [ ('5(a-2b)', L(5) * (L('a') + -(L(2) * 'b'))), ('-(3a+6b)', -(L(3) * L('a') + L(6) * 'b')), ('18-(a-12)', L(18) + -(L('a') + -L(12))), ('-p-q+5(p-q)-3q-2(p-q)', -L('p') + -L('q') + L(5) * (L('p') + -L('q')) + -(L(3) * 'q') \ + - (L(2) * (L('p') + -L('q'))) ), ('(2+3/7)^4', N('^', N('+', L(2), N('/', L(3), L(7))), L(4)) ), ('x3*x2*x', N('*', N('*', N('^', L('x'), L(3)), N('^', L('x'), L(2))), L('x') ) ), ('-x3*-2x5', N('*', N('*', N('-', N('^', L('x'), L(3))), N('-', L(2))), N('^', L('x'), L(5)) ) ), ('(7x2y3)^2/(7x2y3)', N('/', N('^', N('*', N('*', L(7), N('^', L('x'), L(2))), N('^', L('y'), L(3)) ), L(2)), N('*', N('*', L(7), N('^', L('x'), L(2))), N('^', L('y'), L(3)) ) ) ), ])