Skip to content

Commit b8850ed

Browse files
Add unit tests for BDDs
This tests a few more cases with BDDs. In particular, the last case would have failed before the bugfix for the BDD cache.
1 parent 09aae3b commit b8850ed

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

unit/solvers/prop/bdd_expr.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,45 @@ SCENARIO("bdd_expr", "[core][solver][prop][bdd_expr]")
6565
}
6666
}
6767
}
68+
69+
GIVEN("(!a | b) xor (a => b) ")
70+
{
71+
const symbol_exprt a("a", bool_typet());
72+
const symbol_exprt b("b", bool_typet());
73+
const bddt bdd = bdd_expr_converter.from_expr(
74+
xor_exprt{or_exprt{not_exprt{a}, b}, implies_exprt{a, b}});
75+
THEN("It reduces to false")
76+
{
77+
REQUIRE(bdd.is_false());
78+
}
79+
}
80+
81+
GIVEN("e = (a | b) xor (c | d)")
82+
{
83+
const symbol_exprt a("a", bool_typet());
84+
const symbol_exprt b("b", bool_typet());
85+
const symbol_exprt c("c", bool_typet());
86+
const symbol_exprt d("d", bool_typet());
87+
88+
const xor_exprt expr{or_exprt{a, b}, or_exprt{c, d}};
89+
const bddt bdd = bdd_expr_converter.from_expr(expr);
90+
91+
THEN("e xor e is false")
92+
{
93+
REQUIRE(bdd.bdd_xor(bdd_expr_converter.from_expr(expr)).is_false());
94+
}
95+
96+
THEN("e xor !e is true")
97+
{
98+
REQUIRE(
99+
bdd.bdd_xor(bdd_expr_converter.from_expr(not_exprt{expr})).is_true());
100+
}
101+
102+
THEN("Converting to expr and back to BDD gives the same BDD")
103+
{
104+
const exprt expr_of_bdd = bdd_expr_converter.as_expr(bdd);
105+
const bddt bdd_of_expr = bdd_expr_converter.from_expr(expr_of_bdd);
106+
REQUIRE(bdd_of_expr.equals(bdd));
107+
}
108+
}
68109
}

0 commit comments

Comments
 (0)