test_leiden_oefenopgave.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. from unittest import TestCase
  2. from src.parser import Parser
  3. from tests.parser import ParserWrapper
  4. def reduce(exp, **kwargs):
  5. return ParserWrapper(Parser, **kwargs).run([exp]).reduce()
  6. class TestLeidenOefenopgave(TestCase):
  7. def test_1(self):
  8. return
  9. for exp, solution in [
  10. ('-5(x2 -3x + 6)', '-30 + 15 * x - 5 * x ^ 2'),
  11. ('(x+1)^2', 'x ^ 2 + 2 * x + 1'),
  12. ('(x-1)^2', 'x ^ 2 - 2 * x + 1'),
  13. ('(2x+x)*x', '3 * x ^ 2'),
  14. ('-2(6x-4)^2*x', '-72 * x^3 + 96 * x ^ 2 + 32 * x'),
  15. ('(4x + 5) * -(5 - 4x)', '16x^2 - 25'),
  16. ]:
  17. self.assertEqual(str(reduce(exp)), solution)
  18. def test_2(self):
  19. pass
  20. def test_3(self):
  21. pass
  22. def test_4(self):
  23. return
  24. for exp, solution in [
  25. ('2/15 + 1/4', '23/60'),
  26. ('2/7 - 4/11', '-6/77'),
  27. ('(7/3) * (3/5)', '7/5'),
  28. ('(3/4) / (5/6)', '9/10'),
  29. ('1/4 * 1/x', '1/(4x)'),
  30. ('(3/x^2) / (x/7)', '21/x^3'),
  31. ('1/x + 2/(x+1)', '(3x + 1) / (x * (x + 1))'),
  32. ]:
  33. self.assertEqual(str(reduce(exp)), solution)