test_rewrite.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. from tests.rulestestcase import RulesTestCase as TestCase
  16. class TestRewrite(TestCase):
  17. def test_addition_rewrite(self):
  18. self.assertRewrite([
  19. '2 + 3 + 4',
  20. '5 + 4',
  21. '9',
  22. ])
  23. def test_addition_identifiers_rewrite(self):
  24. self.assertRewrite([
  25. '2 + 3a + 4',
  26. '6 + 3a',
  27. ])
  28. def test_division_rewrite(self):
  29. self.assertRewrite([
  30. '2/7 - 4/11',
  31. '22 / 77 - 28 / 77',
  32. '(22 - 28) / 77',
  33. '(-6) / 77',
  34. '-6 / 77',
  35. ])