Преглед изворни кода

Added unit tests for the provided 'Leiden Oefenopgaves'.

Sander Mathijs van Veen пре 14 година
родитељ
комит
be7e4a4649
1 измењених фајлова са 41 додато и 0 уклоњено
  1. 41 0
      tests/test_leiden_oefenopgave.py

+ 41 - 0
tests/test_leiden_oefenopgave.py

@@ -0,0 +1,41 @@
+from unittest import TestCase
+
+from src.parser import Parser
+from tests.parser import ParserWrapper
+
+
+def reduce(exp, **kwargs):
+    return ParserWrapper(Parser, **kwargs).run([exp]).reduce()
+
+
+class TestLeidenOefenopgave(TestCase):
+    def test_1(self):
+        return
+        for exp, solution in [
+                ('-5(x2 -3x + 6)',       '-30 + 15 * x - 5 * x ^ 2'),
+                ('(x+1)^2',              'x ^ 2 + 2 * x + 1'),
+                ('(x-1)^2',              'x ^ 2 - 2 * x + 1'),
+                ('(2x+x)*x',             '3 * x ^ 2'),
+                ('-2(6x-4)^2*x',         '-72 * x^3 + 96 * x ^ 2 + 32 * x'),
+                ('(4x + 5) * -(5 - 4x)', '16x^2 - 25'),
+                ]:
+            self.assertEqual(str(reduce(exp)), solution)
+
+    def test_2(self):
+        pass
+
+    def test_3(self):
+        pass
+
+    def test_4(self):
+        return
+        for exp, solution in [
+                ('2/15 + 1/4',      '23/60'),
+                ('2/7 - 4/11',      '-6/77'),
+                ('(7/3) * (3/5)',   '7/5'),
+                ('(3/4) / (5/6)',   '9/10'),
+                ('1/4 * 1/x',       '1/(4x)'),
+                ('(3/x^2) / (x/7)', '21/x^3'),
+                ('1/x + 2/(x+1)',   '(3x + 1) / (x * (x + 1))'),
+                ]:
+            self.assertEqual(str(reduce(exp)), solution)