test_leiden_oefenopgave.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. '-5 * x ^ 2 - 5 * -3x - 5 * 6',
  6. '-5 * x ^ 2 - -15x - 5 * 6',
  7. # FIXME: '-5 * x ^ 2 - 5 * -3x - 30',
  8. ], #'-30 + 15 * x - 5 * x ^ 2'],
  9. ]:
  10. self.assertRewrite(chain)
  11. return
  12. for exp, solution in [
  13. ('-5(x2 - 3x + 6)', '-30 + 15 * x - 5 * x ^ 2'),
  14. ('(x+1)^2', 'x ^ 2 + 2 * x + 1'),
  15. ('(x-1)^2', 'x ^ 2 - 2 * x + 1'),
  16. ('(2x+x)*x', '3 * x ^ 2'),
  17. ('-2(6x-4)^2*x', '-72 * x^3 + 96 * x ^ 2 + 32 * x'),
  18. ('(4x + 5) * -(5 - 4x)', '16x^2 - 25'),
  19. ]:
  20. self.assertEqual(str(rewrite(exp)), solution)
  21. def test_2(self):
  22. pass
  23. def test_3(self):
  24. pass
  25. def test_4(self):
  26. for exp, solution in [
  27. ('2/15 + 1/4', '8 / 60 + 15 / 60'),
  28. ('8/60 + 15/60', '(8 + 15) / 60'),
  29. ('(8 + 15) / 60', '23 / 60'),
  30. ('2/7 - 4/11', '22 / 77 - 28 / 77'),
  31. ('22/77 - 28/77', '(22 - 28) / 77'),
  32. ('(22 - 28)/77', '-6 / 77'),
  33. # FIXME: ('(7/3) * (3/5)', '7 / 5'),
  34. # FIXME: ('(3/4) / (5/6)', '9 / 10'),
  35. # FIXME: ('1/4 * 1/x', '1 / (4x)'),
  36. # FIXME: ('(3/x^2) / (x/7)', '21 / x^3'),
  37. # FIXME: ('1/x + 2/(x+1)', '(3x + 1) / (x * (x + 1))'),
  38. ]:
  39. self.assertEqual(str(rewrite(exp)), solution)