test_leiden_oefenopgave.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from unittest import TestCase
  2. from src.parser import Parser
  3. from tests.parser import ParserWrapper
  4. def rewrite(exp, **kwargs):
  5. return ParserWrapper(Parser, **kwargs).run([exp, '@'])
  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(rewrite(exp)), solution)
  18. def test_2(self):
  19. pass
  20. def test_3(self):
  21. pass
  22. def test_4(self):
  23. for exp, solution in [
  24. ('2/15 + 1/4', '8 / 60 + 15 / 60'),
  25. ('8/60 + 15/60', '(8 + 15) / 60'),
  26. ('(8 + 15) / 60', '23 / 60'),
  27. # FIXME: ('2/7 - 4/11', '-6 / 77'),
  28. # FIXME: ('(7/3) * (3/5)', '7 / 5'),
  29. # FIXME: ('(3/4) / (5/6)', '9 / 10'),
  30. # FIXME: ('1/4 * 1/x', '1 / (4x)'),
  31. # FIXME: ('(3/x^2) / (x/7)', '21 / x^3'),
  32. # FIXME: ('1/x + 2/(x+1)', '(3x + 1) / (x * (x + 1))'),
  33. ]:
  34. self.assertEqual(str(rewrite(exp)), solution)