test_b1_ch10.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import unittest
  2. from src.parser import Parser
  3. from src.node import ExpressionNode as N, ExpressionLeaf as L
  4. from tests.parser import run_expressions
  5. class TestB1Ch10(unittest.TestCase):
  6. def test_diagnostic_test(self):
  7. run_expressions(Parser, [
  8. ('5(a-2b)', L(5) * (L('a') + -(L(2) * 'b'))),
  9. ('-(3a+6b)', -(L(3) * L('a') + L(6) * 'b')),
  10. ('18-(a-12)', L(18) + -(L('a') + -L(12))),
  11. ('-p-q+5(p-q)-3q-2(p-q)',
  12. -L('p') + -L('q') + L(5) * (L('p') + -L('q')) + -(L(3) * 'q') \
  13. + - (L(2) * (L('p') + -L('q')))
  14. ),
  15. ('(2+3/7)^4',
  16. N('^', N('+', L(2), N('/', L(3), L(7))), L(4))
  17. ),
  18. ('x3*x2*x',
  19. N('*',
  20. N('*',
  21. N('^', L('x'), L(3)),
  22. N('^', L('x'), L(2))),
  23. L('x')
  24. )
  25. ),
  26. ('-x3*-2x5',
  27. N('*',
  28. N('*',
  29. N('-', N('^', L('x'), L(3))),
  30. N('-', L(2))),
  31. N('^', L('x'), L(5))
  32. )
  33. ),
  34. ('(7x2y3)^2/(7x2y3)',
  35. N('/',
  36. N('^',
  37. N('*',
  38. N('*', L(7), N('^', L('x'), L(2))),
  39. N('^', L('y'), L(3))
  40. ),
  41. L(2)),
  42. N('*',
  43. N('*', L(7), N('^', L('x'), L(2))),
  44. N('^', L('y'), L(3))
  45. )
  46. )
  47. ),
  48. ])