Search in sources :

Example 31 with Expr

use of com.microsoft.z3.Expr in project bmoth by hhu-stups.

the class StateTest method testEquals.

@Test
public void testEquals() {
    HashMap<String, Expr> map = new HashMap<>();
    map.put("a", z3Context.mkInt(1));
    map.put("b", z3Context.mkInt(2));
    State s = new State(map);
    State s2 = new State(map);
    assertEqualsImplementedCorrectly(s);
    assertEqualsImplementedCorrectly(s, s2);
    s2 = new State(map);
    State s3 = new State(map);
    assertEqualsImplementedCorrectly(s2);
    assertEqualsImplementedCorrectly(s2, s3);
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Example 32 with Expr

use of com.microsoft.z3.Expr in project bmoth by hhu-stups.

the class StateTest method testStateEquals2.

@Test
public void testStateEquals2() throws Exception {
    HashMap<String, Expr> map1 = new HashMap<>();
    HashMap<String, Expr> map2 = new HashMap<>();
    map1.put("x", z3Context.mkInt(11));
    map1.put("y", z3Context.mkInt(12));
    map2.put("x", z3Context.mkInt(11));
    State state1 = new State(map1);
    State state2 = new State(map2);
    assertNotEquals(state1, state2);
    assertNotEquals(state1.hashCode(), state2.hashCode());
}
Also used : Expr(com.microsoft.z3.Expr) HashMap(java.util.HashMap) State(de.bmoth.modelchecker.State) Test(org.junit.Test)

Example 33 with Expr

use of com.microsoft.z3.Expr in project bmoth by hhu-stups.

the class Z3ConnectionTest method testQuantifiedFormula.

@Test
public void testQuantifiedFormula() {
    Expr a = z3Context.mkIntConst("a");
    Expr b = z3Context.mkIntConst("b");
    BoolExpr constraint = z3Context.mkAnd(z3Context.mkEq(a, b), z3Context.mkEq(a, z3Context.mkInt(5)), z3Context.mkEq(b, z3Context.mkInt(7)));
    constraint = z3Context.mkExists(new Expr[] { a, b }, constraint, 1, null, null, null, null);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    assertEquals(Status.UNSATISFIABLE, check);
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 34 with Expr

use of com.microsoft.z3.Expr in project bmoth by hhu-stups.

the class Z3ConnectionTest method testSimpleCallToZ3.

@Test
public void testSimpleCallToZ3() {
    // a = b & a = 5
    Expr a = z3Context.mkIntConst("a");
    Expr b = z3Context.mkIntConst("b");
    BoolExpr constraint = z3Context.mkAnd(z3Context.mkEq(a, b), z3Context.mkEq(a, z3Context.mkInt(5)));
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    assertEquals(Status.SATISFIABLE, check);
    assertEquals(z3Context.mkInt(5), z3Solver.getModel().eval(a, true));
    assertEquals(z3Context.mkInt(5), z3Solver.getModel().eval(b, true));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Example 35 with Expr

use of com.microsoft.z3.Expr in project bmoth by hhu-stups.

the class BooleanFormulaEvaluationTest method testSimpleBooleanFormula.

@Test
public void testSimpleBooleanFormula() throws Exception {
    String formula = "x = TRUE & y = FALSE";
    // getting the translated z3 representation of the formula
    BoolExpr constraint = FormulaToZ3Translator.translatePredicate(formula, z3Context);
    z3Solver.add(constraint);
    Status check = z3Solver.check();
    Expr x = z3Context.mkBoolConst("x");
    Expr y = z3Context.mkBoolConst("y");
    assertEquals(Status.SATISFIABLE, check);
    assertEquals(z3Context.mkBool(true), z3Solver.getModel().eval(x, true));
    assertEquals(z3Context.mkBool(false), z3Solver.getModel().eval(y, false));
}
Also used : Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) BoolExpr(com.microsoft.z3.BoolExpr) Expr(com.microsoft.z3.Expr) Test(org.junit.Test)

Aggregations

BoolExpr (com.microsoft.z3.BoolExpr)28 Expr (com.microsoft.z3.Expr)27 Test (org.junit.Test)19 HashMap (java.util.HashMap)12 Status (com.microsoft.z3.Status)11 BitVecExpr (com.microsoft.z3.BitVecExpr)10 ArithExpr (com.microsoft.z3.ArithExpr)8 CommunityVar (org.batfish.symbolic.CommunityVar)6 State (de.bmoth.modelchecker.State)5 Ip (org.batfish.datamodel.Ip)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Map (java.util.Map)4 BatfishException (org.batfish.common.BatfishException)4 Prefix (org.batfish.datamodel.Prefix)4 BooleanExpr (org.batfish.datamodel.routing_policy.expr.BooleanExpr)4 Protocol (org.batfish.symbolic.Protocol)4 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 MatchProtocol (org.batfish.datamodel.routing_policy.expr.MatchProtocol)3