test_leiden_oefenopgave.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from tests.rulestestcase import RulesTestCase as TestCase, rewrite
  2. class TestLeidenOefenopgave(TestCase):
  3. def test_1(self):
  4. for chain in [['-5(x2 - 3x + 6)', '-5(x ^ 2 - 3x) - 5 * 6',
  5. # FIXME: '-5 * x ^ 2 - 5 * -3x - 5 * 6',
  6. # FIXME: '-5 * x ^ 2 - 5 * -3x - 30',
  7. ], #'-30 + 15 * x - 5 * x ^ 2'],
  8. ]:
  9. self.assertRewrite(chain)
  10. return
  11. for exp, solution in [
  12. ('-5(x2 - 3x + 6)', '-30 + 15 * x - 5 * x ^ 2'),
  13. ('(x+1)^2', 'x ^ 2 + 2 * x + 1'),
  14. ('(x-1)^2', 'x ^ 2 - 2 * x + 1'),
  15. ('(2x+x)*x', '3 * x ^ 2'),
  16. ('-2(6x-4)^2*x', '-72 * x^3 + 96 * x ^ 2 + 32 * x'),
  17. ('(4x + 5) * -(5 - 4x)', '16x^2 - 25'),
  18. ]:
  19. self.assertEqual(str(rewrite(exp)), solution)
  20. def test_2(self):
  21. pass
  22. def test_3(self):
  23. pass
  24. def test_4(self):
  25. for exp, solution in [
  26. ('2/15 + 1/4', '8 / 60 + 15 / 60'),
  27. ('8/60 + 15/60', '(8 + 15) / 60'),
  28. ('(8 + 15) / 60', '23 / 60'),
  29. ('2/7 - 4/11', '22 / 77 - 28 / 77'),
  30. ('22/77 - 28/77', '(22 - 28) / 77'),
  31. ('(22 - 28)/77', '-6 / 77'),
  32. # FIXME: ('(7/3) * (3/5)', '7 / 5'),
  33. # FIXME: ('(3/4) / (5/6)', '9 / 10'),
  34. # FIXME: ('1/4 * 1/x', '1 / (4x)'),
  35. # FIXME: ('(3/x^2) / (x/7)', '21 / x^3'),
  36. # FIXME: ('1/x + 2/(x+1)', '(3x + 1) / (x * (x + 1))'),
  37. ]:
  38. self.assertEqual(str(rewrite(exp)), solution)