use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class IpSpaceBooleanExprTransformerTest method testVisitIpWildcardSetIpSpace.
@Test
public void testVisitIpWildcardSetIpSpace() {
IpWildcard includeWildcard = new IpWildcard("1.1.1.1");
IpWildcard excludeWildcard = new IpWildcard("2.2.2.2");
IpWildcardSetIpSpace ipSpace = IpWildcardSetIpSpace.builder().including(includeWildcard).excluding(excludeWildcard).build();
BooleanExpr expr = ipSpace.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
BooleanExpr includeExpr = includeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
BooleanExpr excludeExpr = excludeWildcard.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
assertThat(expr, equalTo(new AndExpr(ImmutableList.of(new NotExpr(excludeExpr), includeExpr))));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyAndExprFalseConjunct.
/**
* Test simplifications: false AND E --> false E AND false --> false.
*/
@Test
public void testSimplifyAndExprFalseConjunct() {
BooleanExpr p1 = newAtom();
AndExpr leftFalse = new AndExpr(of(FalseExpr.INSTANCE, p1));
AndExpr rightFalse = new AndExpr(of(p1, FalseExpr.INSTANCE));
assertThat(simplifyBooleanExpr(leftFalse), equalTo(FalseExpr.INSTANCE));
assertThat(simplifyBooleanExpr(rightFalse), equalTo(FalseExpr.INSTANCE));
}
use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.
the class SimplifierTest method testSimplifyOr1.
/**
* Test that an OR node with a single child (other than TRUE or FALSE) simplifies to that child.
*/
@Test
public void testSimplifyOr1() {
BooleanExpr p1 = newAtom();
OrExpr or = new OrExpr(of(p1));
assertThat(simplifyBooleanExpr(or), equalTo(p1));
}
use of org.batfish.z3.expr.BooleanExpr 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.BooleanExpr 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));
}
Aggregations