use of org.batfish.z3.expr.IfExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyIfAntecedentStaticallyConsequent.
/**
* Test that an IF with antecedent statically determinable to be TRUE simplifies to the
* consequent.
*/
@Test
public void testSimplifyIfAntecedentStaticallyConsequent() {
BooleanExpr p1 = newAtom();
assertThat(simplifyBooleanExpr(new IfExpr(TrueExpr.INSTANCE, p1)), equalTo(p1));
assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(TrueExpr.INSTANCE)), p1)), equalTo(p1));
}
use of org.batfish.z3.expr.IfExpr in project batfish by batfish.
the class BoolExprTransformerTest method testVisitIfExpr.
@Test
public void testVisitIfExpr() {
BooleanExpr p1Batfish = newBooleanAtom();
BooleanExpr p2Batfish = newBooleanAtom();
BoolExpr p1Z3 = toBoolExpr(p1Batfish, _input, _nodContext);
BoolExpr p2Z3 = toBoolExpr(p2Batfish, _input, _nodContext);
assertThat(toBoolExpr(new IfExpr(p1Batfish, p2Batfish), _input, _nodContext), equalTo(_ctx.mkImplies(p1Z3, p2Z3)));
}
use of org.batfish.z3.expr.IfExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyIfStaticallyTrue.
/**
* Test that an IF with antecedent statically FALSE, or consequent statically TRUE, or antecedent
* statically equal to consequent simplifies to TRUE.
*/
@Test
public void testSimplifyIfStaticallyTrue() {
BooleanExpr p1 = newAtom();
// Antecedent is false
assertThat(simplifyBooleanExpr(new IfExpr(FalseExpr.INSTANCE, newAtom())), equalTo(TrueExpr.INSTANCE));
assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(FalseExpr.INSTANCE)), newAtom())), equalTo(TrueExpr.INSTANCE));
// Consequent is true
assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), TrueExpr.INSTANCE)), equalTo(TrueExpr.INSTANCE));
assertThat(simplifyBooleanExpr(new IfExpr(newAtom(), new NotExpr(FalseExpr.INSTANCE))), equalTo(TrueExpr.INSTANCE));
// Antecedent == Consequent
assertThat(simplifyBooleanExpr(new IfExpr(p1, p1)), equalTo(TrueExpr.INSTANCE));
assertThat(simplifyBooleanExpr(new IfExpr(new NotExpr(new NotExpr(p1)), p1)), equalTo(TrueExpr.INSTANCE));
}
use of org.batfish.z3.expr.IfExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyIfUnchanged.
/**
* Test that an IF with unsimplifiable antecedent and consequent is unchanged by simplification.
*/
@Test
public void testSimplifyIfUnchanged() {
BooleanExpr p1 = newAtom();
BooleanExpr p2 = newAtom();
BooleanExpr ifExpr = new IfExpr(p1, p2);
assertThat(simplifyBooleanExpr(ifExpr), sameInstance(ifExpr));
}
use of org.batfish.z3.expr.IfExpr in project batfish by batfish.
the class Simplifier method visitIfExpr.
@Override
public BooleanExpr visitIfExpr(IfExpr ifExpr) {
BooleanExpr oldAntecedent = ifExpr.getAntecedent();
BooleanExpr oldConsequent = ifExpr.getConsequent();
BooleanExpr newAntecedent = simplifyBooleanExpr(oldAntecedent);
BooleanExpr newConsequent = simplifyBooleanExpr(oldConsequent);
if (newAntecedent == FalseExpr.INSTANCE || newConsequent == TrueExpr.INSTANCE || newAntecedent.equals(newConsequent)) {
return TrueExpr.INSTANCE;
} else if (newAntecedent == TrueExpr.INSTANCE) {
return newConsequent;
} else if (newAntecedent != oldAntecedent || newConsequent != oldConsequent) {
return new IfExpr(newAntecedent, newConsequent);
} else {
return ifExpr;
}
}
Aggregations