Преглед на файлове

Fixed leiden oefenopgaves test cases 4.3 and 4.5.

Sander Mathijs van Veen преди 14 години
родител
ревизия
5acc67df21
променени са 3 файла, в които са добавени 30 реда и са изтрити 6 реда
  1. 19 0
      TODO
  2. 3 2
      src/strategy.py
  3. 8 4
      tests/test_leiden_oefenopgave.py

+ 19 - 0
TODO

@@ -70,3 +70,22 @@ Division of 0 by 1 reduces to 0.
    >>> @
    2 / 7 + 4 / 11
 
+
+ - Cancel terms before multiplying constants: (3 * ...) / (3 * ...) -> ... / ...
+    >>> (7/3)*(3/5)
+    7 / 3 * (3 / 5)
+    >>> ??
+    Expand fraction with nominator greater than denominator 7 / 3 to an integer
+    plus a fraction.
+    Multiply fractions 7 / 3 and 3 / 5.
+    >>> @
+    7 * 3 / (3 * 5)
+    >>> ?
+    Multiply constant 7 with 3.
+    >>> @
+    21 / (3 * 5)
+    >>> @
+    21 / 15
+    >>> @
+    7 / 5
+

+ 3 - 2
src/strategy.py

@@ -1,5 +1,5 @@
 from rules.sort import move_constant
-from rules.numerics import reduce_fraction_constants
+from rules.numerics import reduce_fraction_constants, fraction_to_int_fraction
 
 
 def pick_suggestion(possibilities):
@@ -8,7 +8,8 @@ def pick_suggestion(possibilities):
 
     # TODO: pick the best suggestion.
     for suggestion, p in enumerate(possibilities + [None]):
-        if p and p.handler not in [move_constant, reduce_fraction_constants]:
+        if p and p.handler not in [move_constant, fraction_to_int_fraction,
+                reduce_fraction_constants]:
             break
 
     if not p:

+ 8 - 4
tests/test_leiden_oefenopgave.py

@@ -143,14 +143,18 @@ class TestLeidenOefenopgave(TestCase):
         self.assertRewrite(['2/7 - 4/11', '22 / 77 - 28 / 77',
                             '(22 - 28) / 77', '-6 / 77'])
 
-    #def test_4_3(self):
-    #    self.assertRewrite(['(7/3) * (3/5)', '7 / 5'])
+    def test_4_3(self):
+        self.assertRewrite(['(7/3) * (3/5)',
+                            '7 * 3 / (3 * 5)',
+                            '21 / (3 * 5)',
+                            '21 / 15',
+                            '7 / 5'])
 
     #def test_4_4(self):
     #    self.assertRewrite(['(3/4) / (5/6)', '9 / 10'])
 
-    #def test_4_5(self):
-    #    self.assertRewrite(['1/4 * 1/x', '1 / (4x)'])
+    def test_4_5(self):
+        self.assertRewrite(['1/4 * 1/x', '1 / 4 / x', ])  # FIXME: '1 / (4x)'])
 
     #def test_4_6(self):
     #    self.assertRewrite(['(3/x^2) / (x/7)', '21 / x^3'])