Search in sources :

Example 66 with Expr

use of com.google.api.expr.v1alpha1.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 67 with Expr

use of com.google.api.expr.v1alpha1.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 68 with Expr

use of com.google.api.expr.v1alpha1.Expr in project bmoth by hhu-stups.

the class LiftsTest method testTargetAndCurrentCorrespond.

@Test
public void testTargetAndCurrentCorrespond() {
    MachineNode simpleMachineWithViolation = parseMachineFromFile(dir + "TargetAndCurrentCorrespond.mch");
    ModelCheckingResult result = ExplicitStateModelChecker.check(simpleMachineWithViolation);
    assertEquals(false, result.isCorrect());
    Expr targetFloor = result.getLastState().getValues().get("target_floor");
    Expr currentFloor = result.getLastState().getValues().get("current_floor");
    assertNotEquals(targetFloor.toString(), currentFloor.toString());
}
Also used : Expr(com.microsoft.z3.Expr) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) Test(org.junit.Test)

Example 69 with Expr

use of com.google.api.expr.v1alpha1.Expr in project spoon by INRIA.

the class CommonUtils method getTargetValue.

/**
 * Gets target expression value by going from left to right.
 * For example, 'a.b' is calculated as follows: memory[T2.b][memory[T1.a][a]]
 */
public static IntExpr getTargetValue(Context context, Map<CtReference, Expr> variablesMap, Memory memory, CtExpression<?> target) {
    Deque<CtExpression> targets = new ArrayDeque<>();
    while (target instanceof CtTargetedExpression) {
        targets.addFirst(target);
        target = ((CtTargetedExpression) target).getTarget();
    }
    targets.addFirst(target);
    // Traverse all targets left to right
    IntExpr targetValue = null;
    for (CtExpression t : targets) {
        if (t instanceof CtFieldRead) {
            targetValue = (IntExpr) memory.read(((CtFieldRead) t).getVariable(), targetValue);
        } else if (t instanceof CtArrayRead) {
            CtArrayRead arrayRead = (CtArrayRead) t;
            CtExpression index = arrayRead.getIndexExpression();
            Expr arrayIndex = (Expr) index.getMetadata("value");
            targetValue = (IntExpr) memory.readArray((CtArrayTypeReference) arrayRead.getTarget().getType(), targetValue, arrayIndex);
        } else if (t instanceof CtVariableRead) {
            targetValue = (IntExpr) variablesMap.get(((CtVariableRead) t).getVariable());
        } else if (t instanceof CtTypeAccess) {
            targetValue = (IntExpr) variablesMap.get(TypeUtils.getActualType(t));
            if (targetValue == null) {
                targetValue = (IntExpr) context.mkFreshConst("", context.getIntSort());
                variablesMap.put(TypeUtils.getActualType(t), targetValue);
            }
        } else if (t instanceof CtThisAccess) {
            targetValue = context.mkInt(Memory.thisPointer());
        } else {
            // Impure functions and other unknown stuff
            targetValue = (IntExpr) context.mkFreshConst("", context.getIntSort());
        }
    }
    return targetValue;
}
Also used : IntExpr(com.microsoft.z3.IntExpr) Expr(com.microsoft.z3.Expr) IntExpr(com.microsoft.z3.IntExpr) CtArrayTypeReference(spoon.reflect.reference.CtArrayTypeReference) ArrayDeque(java.util.ArrayDeque)

Example 70 with Expr

use of com.google.api.expr.v1alpha1.Expr in project cel-java by projectnessie.

the class ConformanceServerTest method Parse.

/**
 * TestParse tests the Parse method.
 */
@Test
void Parse() {
    ParseRequest req = ParseRequest.newBuilder().setCelSource("1 + 1").build();
    ParseResponse res = stub.parse(req);
    assertThat(res.isInitialized()).isTrue();
    assertThat(res.getParsedExpr().isInitialized()).isTrue();
    // Could check against 'parsed' above,
    // but the expression ids are arbitrary,
    // and explicit comparison logic is about as
    // much work as normalization would be.
    assertThat(res.getParsedExpr().getExpr().isInitialized()).isTrue();
    assertThat(res.getParsedExpr().getExpr().getExprKindCase()).isSameAs(ExprKindCase.CALL_EXPR);
    Call c = res.getParsedExpr().getExpr().getCallExpr();
    assertThat(c.getTarget().isInitialized()).isTrue();
    assertThat(c.getFunction()).isEqualTo("_+_");
    assertThat(c.getArgsCount()).isEqualTo(2);
    for (Expr a : c.getArgsList()) {
        assertThat(a.getExprKindCase()).isSameAs(ExprKindCase.CONST_EXPR);
        Constant l = a.getConstExpr();
        assertThat(l.getConstantKindCase()).isSameAs(ConstantKindCase.INT64_VALUE);
        assertThat(l.getInt64Value()).isEqualTo(1);
    }
}
Also used : Call(com.google.api.expr.v1alpha1.Expr.Call) ExprCall(org.projectnessie.cel.TestExpr.ExprCall) ParsedExpr(com.google.api.expr.v1alpha1.ParsedExpr) Expr(com.google.api.expr.v1alpha1.Expr) CheckedExpr(com.google.api.expr.v1alpha1.CheckedExpr) Constant(com.google.api.expr.v1alpha1.Constant) ParseRequest(com.google.api.expr.v1alpha1.ParseRequest) ParseResponse(com.google.api.expr.v1alpha1.ParseResponse) Test(org.junit.jupiter.api.Test)

Aggregations

Expr (edu.stanford.CVC4.Expr)57 Test (org.junit.Test)55 CVC4.vectorExpr (edu.stanford.CVC4.vectorExpr)49 SExpr (edu.stanford.CVC4.SExpr)42 Expr (com.microsoft.z3.Expr)32 Result (edu.stanford.CVC4.Result)32 Rational (edu.stanford.CVC4.Rational)28 Expr (com.google.api.expr.v1alpha1.Expr)23 BoolExpr (com.microsoft.z3.BoolExpr)22 ArrayType (edu.stanford.CVC4.ArrayType)12 BitVectorType (edu.stanford.CVC4.BitVectorType)12 Status (com.microsoft.z3.Status)11 Type (edu.stanford.CVC4.Type)11 HashMap (java.util.HashMap)11 Test (org.junit.jupiter.api.Test)11 ParsedExpr (com.google.api.expr.v1alpha1.ParsedExpr)10 CheckedExpr (com.google.api.expr.v1alpha1.CheckedExpr)9 ArithExpr (com.microsoft.z3.ArithExpr)8 BitVecExpr (com.microsoft.z3.BitVecExpr)8 Val (org.projectnessie.cel.common.types.ref.Val)7