Ver código fonte

Added type check to ExpressionLeaf equality check.

- Now, integer- and float-leaves are never considered equal.
Taddeus Kroes 14 anos atrás
pai
commit
92f3a4e97f
2 arquivos alterados com 7 adições e 8 exclusões
  1. 4 5
      src/node.py
  2. 3 3
      tests/test_rules_powers.py

+ 4 - 5
src/node.py

@@ -242,13 +242,12 @@ class ExpressionLeaf(Leaf, ExpressionBase):
         self.type = TYPE_MAP[type(args[0])]
 
     def __eq__(self, other):
-        if type(other) in (int, float, str):
-            return self.value == other
+        other_type = type(other)
 
-        if other.is_leaf():
-            return self.value == other.value
+        if other_type in TYPE_MAP:
+            return TYPE_MAP[other_type] == self.type and self.value == other
 
-        return False
+        return other.type == self.type and self.value == other.value
 
     def extract_polynome_properties(self):
         """

+ 3 - 3
tests/test_rules_powers.py

@@ -88,14 +88,14 @@ class TestRulesPowers(RulesTestCase):
                 [P(root, remove_negative_exponent, (a, p))])
 
     def test_match_exponent_to_root(self):
-        a, n, m = tree('a,n,m')
-        root = a ** (n / m)
+        a, n, m, l1 = tree('a,n,m,1')
 
+        root = a ** (n / m)
         possibilities = match_exponent_to_root(root)
         self.assertEqualPos(possibilities,
                 [P(root, exponent_to_root, (a, n, m))])
 
-        n.value = 1
+        root = a ** (l1 / m)
         possibilities = match_exponent_to_root(root)
         self.assertEqualPos(possibilities,
                 [P(root, exponent_to_root, (a, 1, m))])