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);
}
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());
}
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());
}
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;
}
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);
}
}
Aggregations