Search in sources :

Example 11 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class IpSpaceBooleanExprTransformerTest method testVisitEmptyIpSpace.

@Test
public void testVisitEmptyIpSpace() {
    BooleanExpr expr = EmptyIpSpace.INSTANCE.accept(SRC_IP_SPACE_BOOLEAN_EXPR_TRANSFORMER);
    assertThat(expr, equalTo(FalseExpr.INSTANCE));
}
Also used : BooleanExpr(org.batfish.z3.expr.BooleanExpr) Test(org.junit.Test)

Example 12 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyAndExprPreserveUnalteredInstance.

/**
 * Test that an unsimplifiable expression is unchanged by simplification.
 */
@Test
public void testSimplifyAndExprPreserveUnalteredInstance() {
    BooleanExpr p1 = newAtom();
    BooleanExpr p2 = newAtom();
    AndExpr and = new AndExpr(of(p1, p2));
    assertThat(simplifyBooleanExpr(and), sameInstance(and));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 13 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyAnd1.

/**
 * Test that an AND node with a single child (other than TRUE or FALSE) simplifies to that child.
 */
@Test
public void testSimplifyAnd1() {
    BooleanExpr p1 = newAtom();
    AndExpr and = new AndExpr(of(p1));
    assertThat(simplifyBooleanExpr(and), equalTo(p1));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 14 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr in project batfish by batfish.

the class SimplifierTest method testSimplifyAndTrue.

/**
 * Test that any TRUE children of an AND node are removed.
 */
@Test
public void testSimplifyAndTrue() {
    BooleanExpr p1 = newAtom();
    BooleanExpr p2 = newAtom();
    AndExpr and = new AndExpr(of(TrueExpr.INSTANCE, p1, TrueExpr.INSTANCE, p2));
    assertThat(simplifyBooleanExpr(and), equalTo(new AndExpr(of(p1, p2))));
}
Also used : AndExpr(org.batfish.z3.expr.AndExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Example 15 with BooleanExpr

use of org.batfish.z3.expr.BooleanExpr 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));
}
Also used : IfExpr(org.batfish.z3.expr.IfExpr) NotExpr(org.batfish.z3.expr.NotExpr) BooleanExpr(org.batfish.z3.expr.BooleanExpr) Simplifier.simplifyBooleanExpr(org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr) Test(org.junit.Test)

Aggregations

BooleanExpr (org.batfish.z3.expr.BooleanExpr)43 Test (org.junit.Test)27 AndExpr (org.batfish.z3.expr.AndExpr)14 NotExpr (org.batfish.z3.expr.NotExpr)13 Simplifier.simplifyBooleanExpr (org.batfish.z3.expr.visitors.Simplifier.simplifyBooleanExpr)13 BasicRuleStatement (org.batfish.z3.expr.BasicRuleStatement)10 ImmutableList (com.google.common.collect.ImmutableList)9 HeaderSpaceMatchExpr (org.batfish.z3.expr.HeaderSpaceMatchExpr)8 BoolExpr (com.microsoft.z3.BoolExpr)7 IfExpr (org.batfish.z3.expr.IfExpr)7 VarIntExpr (org.batfish.z3.expr.VarIntExpr)7 BoolExprTransformer.toBoolExpr (org.batfish.z3.expr.visitors.BoolExprTransformer.toBoolExpr)7 List (java.util.List)6 IpWildcard (org.batfish.datamodel.IpWildcard)6 EqExpr (org.batfish.z3.expr.EqExpr)6 OrExpr (org.batfish.z3.expr.OrExpr)6 QueryStatement (org.batfish.z3.expr.QueryStatement)6 RuleStatement (org.batfish.z3.expr.RuleStatement)6 TransformationRuleStatement (org.batfish.z3.expr.TransformationRuleStatement)6 Ip (org.batfish.datamodel.Ip)5