Commits

tomo cocoa committed ef0aaff

added test cases

  • Participants
  • Parent commits 75b45a2

Comments (0)

Files changed (2)

File logics/prop.py

     return prop._eval(variables)
 
 
-def equivalent(prop1, prop2):
+def equivalent_DNF(prop1, prop2):
     return canonicalize_DNF(prop1) == canonicalize_DNF(prop2)
-#    return canonicalize_CNF(prop1) == canonicalize_CNF(prop2)
+
+
+def equivalent_CNF(prop1, prop2):
+    return canonicalize_CNF(prop1) == canonicalize_CNF(prop2)
+
+
+equivalent = equivalent_DNF
 
 
 def replace_with_And_Or_Not(prop):

File tests/test_prop.py

 s = lp.Var('s')
 
 
+equivs = [(p & ~p, lp.F),
+          (p | ~p, lp.T),
+          (lp.IfThen(lp.IfThen(p, q) & lp.IfThen(q, r), lp.IfThen(p, r)), lp.T),
+          (lp.IfThen(p, q) & lp.IfThen(q, p), lp.Iff(p, q)),
+          (lp.IfThen(p & lp.IfThen(p, q), q), lp.T)
+          ]
+
+
+@pytest.mark.parametrize(
+    ('lhs', 'rhs'),
+    equivs
+)
+def test_equivalent_DNF(lhs, rhs):
+    assert lp.equivalent_DNF(lhs, rhs)
+
+
+@pytest.mark.parametrize(
+    ('lhs', 'rhs'),
+    equivs
+)
+def test_equivalent_CNF(lhs, rhs):
+    assert lp.equivalent_CNF(lhs, rhs)
+
+
 @pytest.mark.parametrize(
     ('prop', 'dnf'),
     [(lp.T, lp.T),
      (lp.IfThen(p, q), (p & q) | ~p),
 
      (lp.Iff(p, p), lp.T),
-     (lp.Iff(p, ~p), lp.F)
+     (lp.Iff(p, ~p), lp.F),
+
+     (lp.IfThen(lp.IfThen(p, q) & lp.IfThen(q, r), lp.IfThen(p, r)), lp.T)
      ]
 )
 def test_canonicalize_DNF(prop, dnf):
      (lp.IfThen(p, q), ~p | q),
 
      (lp.Iff(p, p), lp.T),
-     (lp.Iff(p, ~p), lp.F)
+     (lp.Iff(p, ~p), lp.F),
+
+     (lp.IfThen(lp.IfThen(p, q) & lp.IfThen(q, r), lp.IfThen(p, r)), lp.T)
      ]
 )
 def test_canonicalize_CNF(prop, cnf):