test_validation.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 unittest import TestCase
  16. from src.validation import validate
  17. class TestValidation(TestCase):
  18. def test_simple_success(self):
  19. self.assertTrue(validate('3a + a', '4a'))
  20. def test_simple_failure(self):
  21. self.assertFalse(validate('3a + a', '4a + 1'))
  22. def test_intermediate_success(self):
  23. self.assertTrue(validate('3a + a + b + 2b', '4a + 3b'))
  24. self.assertTrue(validate('a / b / (c / d)', '(ad) / (bc)'))
  25. def test_intermediate_failure(self):
  26. self.assertFalse(validate('3a + a + b + 2b', '4a + 4b'))
  27. #def test_success(self):
  28. # self.assertTrue(validate('x^2 + x - 2x^2 + 3x + 1',
  29. # 'x^2 + 4x - 2x^2 + 1'))
  30. #def test_indefinite_integral(self):
  31. # self.assertTrue(validate('int_2^4 x^2', '4^3/3 - 2^3/3'))
  32. #def test_advanced_failure(self):
  33. # self.assertFalse(validate('(x-1)^3+(x-1)^3', '4a+4b'))
  34. def test_sphere_volume(self):
  35. self.assertTrue(validate('int_(-r)^(r) pi * (r^2 - x^2) dx',
  36. '4 / 3 * pi * r ^ 3'))
  37. #def test_sphere_volume_alternative(self):
  38. # self.assertTrue(validate('int_(-r)^(r) pi * (r^2 - x^2) dx',
  39. # '4 * pi * r ^ 3 / 3'))