test_b1_ch08.py 739 B

1234567891011121314151617181920212223
  1. import unittest
  2. from src.parser import Parser
  3. from src.node import ExpressionLeaf as L
  4. from tests.parser import run_expressions, apply_expressions
  5. class TestB1Ch08(unittest.TestCase):
  6. def test_diagnostic_test_parser(self):
  7. run_expressions(Parser, [
  8. ('6*5^2', L(6) * L(5) ** 2),
  9. ('-5*(-3)^2', (-L(5)) * (-L(3)) ** 2),
  10. ('7p-3p', L(7) * 'p' + (-L(3) * 'p')),
  11. ('-5a*-6', (-L(5)) * 'a' * (-L(6))),
  12. ('3a-8--5-2a', L(3) * 'a' + -L(8) + (--L(5)) + (-L(2) * 'a')),
  13. ])
  14. def test_diagnostic_test_application(self):
  15. apply_expressions(Parser, [
  16. ('7p+2p', 1, (L(7) + 2) * 'p'),
  17. ('7p-3p', 1, (L(7) + -L(3)) * 'p'),
  18. ])