test_validation.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 rulestestcase import RulesTestCase
  16. from src.validation import validate, VALIDATE_SUCCESS as OK, \
  17. VALIDATE_FAILURE as FAIL, VALIDATE_NOPROGRESS as NP
  18. class TestValidation(RulesTestCase):
  19. def test_simple_success(self):
  20. self.assertValidateSuccess('3a + a', '4a')
  21. def test_simple_failure(self):
  22. self.assertValidateFailure('3a + a', '4a + 1')
  23. def test_intermediate_success(self):
  24. self.assertValidateSuccess('3a + a + b + 2b', '4a + 3b')
  25. self.assertValidateSuccess('a / b / (c / d)', '(ad) / (bc)')
  26. def test_intermediate_failure(self):
  27. self.assertValidateFailure('3a + a + b + 2b', '4a + 4b')
  28. def test_success(self):
  29. self.assertValidateSuccess('x^2 + x - 2x^2 + 3x + 1',
  30. 'x^2 + 4x - 2x^2 + 1')
  31. def test_indefinite_integral(self):
  32. self.assertValidateSuccess('int_2^4 x^2', '4^3/3 - 2^3/3')
  33. def test_advanced_failure(self):
  34. self.assertValidateFailure('(x-1)^3+(x-1)^3', '4a+4b')
  35. def test_sphere_volume(self):
  36. self.assertValidateSuccess('int_(-r)^(r) pi * (r^2 - x^2) dx',
  37. '4 / 3 * pi * r ^ 3')
  38. def test_sphere_volume_alternative_notation(self):
  39. self.assertValidateSuccess('int_(-r)^(r) pi * (r^2 - x^2) dx',
  40. '4 * pi * r ^ 3 / 3')
  41. def test_noprogress_simple(self):
  42. self.assertValidateNoprogress('2 + 2', '3 + 1')