def make_predicate_many(statements):
    # TODO: Switch this back to using predicate.Top and predicate.And
    # once the macros are returning Predicate predicates instead of z3 predicates.
    if len(statements) == 0:
        return predicate.Top()
    elif len(statements) == 1:
        return make_predicate(statements[0])
    else:
        predicates = [make_predicate(statement) for statement in statements]
        return predicate.And(*predicates)
Esempio n. 2
0
import predicate
from solver import MySolver
from unittest import TestCase

syndra_true = predicate.Top()
syndra_false = predicate.Bottom()

class SolverTestCase(TestCase):

    def setUp(self):
        self.solver = MySolver("A", "B")

    def test_quick_check_true(self):
        self.assertTrue(self.solver.quick_check(syndra_true))

    def test_quick_check_false(self):
        self.assertFalse(self.solver.quick_check(syndra_false))

    def test_quick_check_pushes_and_pops(self):
        self.assertTrue(self.solver.check())
        self.assertFalse(self.solver.quick_check(syndra_false))
        self.assertTrue(self.solver.check())

    def test_context(self):
        with self.solver.context():
            self.solver.add(syndra_false)
            self.assertFalse(self.solver.check())
        self.assertTrue(self.solver.check())

    def test_add(self):
        with self.solver.context():
Esempio n. 3
0
 def test_or_sat(self):
     p1 = predicate.Bottom()
     p2 = predicate.Top()
     status = solver.quick_check(predicate.Or(p1, p2))
     self.assertTrue(status)
Esempio n. 4
0
 def test_and_unsat(self):
     p1 = predicate.Top()
     p2 = predicate.Bottom()
     status = solver.quick_check(predicate.And(p1, p2))
     self.assertFalse(status)
Esempio n. 5
0
 def test_and_sat(self):
     p1 = predicate.Top()
     p2 = predicate.Top()
     status = solver.quick_check(predicate.And(p1, p2))
     self.assertTrue(status)
Esempio n. 6
0
 def test_modelhasrule_sat(self):
     pred = predicate.ModelHasRule(lambda r: predicate.Top())
     self.assertSat(pred)
Esempio n. 7
0
 def test_top_sat(self):
     self.assertSat(predicate.Top())
Esempio n. 8
0
import atomic_predicate
import datatypes
from labels import ACTIVE, PHOSPHORYLATED
from macros import directly_phosphorylates, directly_activates, phosphorylated_is_active
import predicate
from solver import solver
import z3

# Sanity checks.
assert not predicate.Bottom().check_sat()
assert predicate.Top().check_sat()
assert not predicate.And(predicate.Bottom(), predicate.Top()).check_sat()
assert not predicate.ForAll(predicate.Bottom()).check_sat()
assert predicate.ForAll(predicate.Top()).check_sat()
assert not predicate.Exists(predicate.Bottom()).check_sat()
assert predicate.Exists(predicate.Top()).check_sat()

print "Predicate I: MEK directly phosphorylates ERK in a single step.\nTranslated to z3:"
i = directly_phosphorylates("MEK", "ERK")
print i.get_predicate()

print "\nPredicate II: ERK, when phosphorylated, is always active.\nTranslated to z3:"
ii = phosphorylated_is_active("ERK")
print ii.get_predicate()

print "\nPredicate III: MEK directly activates ERK in a single step.\nTranslated to z3:"
iii = directly_activates("MEK", "ERK")
print iii.get_predicate()

print "\nEach of these predicates is satisfiable (True) on their own: checking..."
assert i.check_sat()
Esempio n. 9
0
 def test_or_sat(self):
     p1 = predicate.Bottom()
     p2 = predicate.Top()
     status = predicate.Or(p1, p2)
     self.assertTrue(status)
Esempio n. 10
0
 def test_and_unsat(self):
     p1 = predicate.Top()
     p2 = predicate.Bottom()
     status = predicate.And(p1, p2)
     self.assertTrue(status)