test_b1_ch08.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # This file is part of TRS (http://math.kompiler.org)
  2. #
  3. # TRS is free software: you can redistribute it and/or modify it under the
  4. # terms of the GNU Affero General Public License as published by the Free
  5. # Software Foundation, either version 3 of the License, or (at your option) any
  6. # later version.
  7. #
  8. # TRS is distributed in the hope that it will be useful, but WITHOUT ANY
  9. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  10. # A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  11. # details.
  12. #
  13. # You should have received a copy of the GNU Affero General Public License
  14. # along with TRS. If not, see <http://www.gnu.org/licenses/>.
  15. import unittest
  16. from src.parser import Parser
  17. from src.node import ExpressionLeaf as L
  18. from tests.parser import run_expressions, apply_expressions
  19. class TestB1Ch08(unittest.TestCase):
  20. def test_diagnostic_test_parser(self):
  21. run_expressions(Parser, [
  22. ('6*5^2', L(6) * L(5) ** 2),
  23. ('-5*(-3)^2', -(L(5) * (-L(3)) ** 2)),
  24. ('7p-3p', L(7) * 'p' + -(L(3) * 'p')),
  25. ('-5a*-6', -(L(5) * 'a' * -L(6))),
  26. ('3a-8--5-2a', L(3) * 'a' + -L(8) + --(L(5)) + -(L(2) * 'a')),
  27. ])
  28. def test_diagnostic_test_application(self):
  29. apply_expressions(Parser, [
  30. ('7p+2p', 1, (L(7) + 2) * 'p'),
  31. ('7p-3p', 1, (L(7) + -L(3)) * 'p'),
  32. ])