Skip to content

Commit 708eeff

Browse files
committed
Make the remaining (relevant) miniBDD catch-style unit tests
1 parent 30f534f commit 708eeff

File tree

3 files changed

+67
-106
lines changed

3 files changed

+67
-106
lines changed

unit/Makefile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,15 @@ N_CATCH_TESTS = $(shell \
116116
-a -not -name "expr_undefined_casts.cpp") | \
117117
grep -c -E "(SCENARIO|TEST_CASE)")
118118

119-
TESTS = miniBDD$(EXEEXT) \
120-
# Empty last line
121-
122-
CLEANFILES = $(CATCH_TEST) $(TESTS) testing-utils/testing-utils$(LIBEXT)
119+
CLEANFILES = $(CATCH_TEST) testing-utils/testing-utils$(LIBEXT)
123120

124121
# only add a dependency for libraries to avoid triggering implicit rules, which
125122
# would cause unnecessary rebuilds
126123
$(filter %$(LIBEXT), CPROVER_LIBS): cprover.dir
127124

128-
all: $(CATCH_TEST) $(TESTS)
125+
all: $(CATCH_TEST)
129126

130-
test: $(CATCH_TEST) $(TESTS)
131-
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
127+
test: $(CATCH_TEST)
132128
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
133129
./$(CATCH_TEST) -l ; fi
134130
./$(CATCH_TEST)
@@ -138,6 +134,3 @@ test: $(CATCH_TEST) $(TESTS)
138134

139135
unit_tests$(EXEEXT): $(OBJ)
140136
$(LINKBIN)
141-
142-
miniBDD$(EXEEXT): miniBDD$(OBJEXT) $(CPROVER_LIBS)
143-
$(LINKBIN)

unit/miniBDD.cpp

Lines changed: 0 additions & 95 deletions
This file was deleted.

unit/solvers/miniBDD/miniBDD.cpp

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313

1414
#include <solvers/miniBDD/miniBDD.h>
1515
#include <solvers/flattening/boolbv.h>
16+
#include <solvers/prop/bdd_expr.h>
1617

17-
#include <util/symbol_table.h>
1818
#include <util/arith_tools.h>
1919
#include <util/expanding_vector.h>
20+
#include <util/format_expr.h>
21+
#include <util/symbol_table.h>
2022

2123
class bdd_propt:public propt
2224
{
@@ -291,4 +293,65 @@ SCENARIO("miniBDD", "[core][solver][miniBDD]")
291293

292294
REQUIRE(!result.is_constant());
293295
}
296+
297+
GIVEN("A bdd for x&y")
298+
{
299+
mini_bdd_mgrt mgr;
300+
301+
mini_bddt final_bdd = mgr.Var("x") & mgr.Var("y");
302+
303+
std::ostringstream oss;
304+
mgr.DumpDot(oss);
305+
306+
const std::string dot_string =
307+
"digraph BDD {\n"
308+
"center = true;\n"
309+
"{ rank = same; { node [style=invis]; \"T\" };\n"
310+
" { node [shape=box,fontsize=24]; \"0\"; }\n"
311+
" { node [shape=box,fontsize=24]; \"1\"; }\n"
312+
"}\n"
313+
"\n"
314+
"{ rank=same; { node [shape=plaintext,fontname="
315+
"\"Times Italic\",fontsize=24] \" y \" }; \"4\"; }\n"
316+
"{ rank=same; { node [shape=plaintext,fontname="
317+
"\"Times Italic\",fontsize=24] \" x \" }; \"3\"; }\n"
318+
"\n"
319+
"{ edge [style = invis]; \" y \" -> \" x \" -> \"T\"; }\n"
320+
"\n"
321+
"\"3\" -> \"1\" [style=solid,arrowsize=\".75\"];\n"
322+
"\"3\" -> \"0\" [style=dashed,arrowsize=\".75\"];\n"
323+
"\n"
324+
"\"4\" -> \"3\" [style=solid,arrowsize=\".75\"];\n"
325+
"\"4\" -> \"0\" [style=dashed,arrowsize=\".75\"];\n"
326+
"\n"
327+
"}\n";
328+
329+
REQUIRE(oss.str() == dot_string);
330+
}
331+
332+
GIVEN("A bdd for (a&b)|!a")
333+
{
334+
symbol_exprt a("a", bool_typet());
335+
symbol_exprt b("b", bool_typet());
336+
337+
or_exprt o(and_exprt(a, b), not_exprt(a));
338+
339+
symbol_tablet symbol_table;
340+
namespacet ns(symbol_table);
341+
342+
{
343+
std::ostringstream oss;
344+
oss << format(o);
345+
REQUIRE(oss.str() == "(a ∧ b) ∨ (¬a)");
346+
}
347+
348+
bdd_exprt t(ns);
349+
t.from_expr(o);
350+
351+
{
352+
std::ostringstream oss;
353+
oss << format(t.as_expr());
354+
REQUIRE(oss.str() == "(¬a) ∨ b");
355+
}
356+
}
294357
}

0 commit comments

Comments
 (0)