Skip to content

Commit 49328be

Browse files
committed
Make the remaining (relevant) miniBDD catch-style unit tests
1 parent 3c42a15 commit 49328be

File tree

5 files changed

+73
-122
lines changed

5 files changed

+73
-122
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ set_target_properties(
6868
json
6969
langapi
7070
linking
71-
miniBDD
7271
pointer-analysis
7372
solvers
7473
test-bigint

unit/CMakeLists.txt

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ file(GLOB_RECURSE sources "*.cpp" "*.h")
33
file(GLOB_RECURSE testing_utils "testing-utils/*.cpp" "testing-utils/*.h")
44

55
list(REMOVE_ITEM sources
6-
# Used in executables
7-
${CMAKE_CURRENT_SOURCE_DIR}/miniBDD.cpp
8-
96
# Don't build
107
${CMAKE_CURRENT_SOURCE_DIR}/elf_reader.cpp
118
${CMAKE_CURRENT_SOURCE_DIR}/smt2_parser.cpp
@@ -48,14 +45,3 @@ add_test(
4845
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
4946
)
5047
set_tests_properties(unit PROPERTIES LABELS "CORE;CBMC")
51-
52-
add_executable(miniBDD miniBDD.cpp)
53-
target_include_directories(miniBDD
54-
PUBLIC
55-
${CBMC_BINARY_DIR}
56-
${CBMC_SOURCE_DIR}
57-
${CMAKE_CURRENT_SOURCE_DIR}
58-
)
59-
target_link_libraries(miniBDD solvers ansi-c)
60-
add_test(NAME miniBDD COMMAND $<TARGET_FILE:miniBDD>)
61-
set_tests_properties(miniBDD PROPERTIES LABELS "CORE;CBMC")

unit/Makefile

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,21 +116,17 @@ 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

130127
clean: testing-utils-clean
131128

132-
test: $(CATCH_TEST) $(TESTS)
133-
$(foreach test,$(TESTS), (echo Running: $(test); ./$(test)) &&) true
129+
test: $(CATCH_TEST)
134130
if ! ./$(CATCH_TEST) -l | grep -q "^$(N_CATCH_TESTS) test cases" ; then \
135131
./$(CATCH_TEST) -l ; fi
136132
./$(CATCH_TEST)
@@ -140,6 +136,3 @@ test: $(CATCH_TEST) $(TESTS)
140136

141137
unit_tests$(EXEEXT): $(OBJ)
142138
$(LINKBIN)
143-
144-
miniBDD$(EXEEXT): miniBDD$(OBJEXT) $(CPROVER_LIBS)
145-
$(LINKBIN)

unit/miniBDD.cpp

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

unit/solvers/miniBDD/miniBDD.cpp

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@
1111

1212
#include <testing-utils/catch.hpp>
1313

14-
#include <solvers/miniBDD/miniBDD.h>
1514
#include <solvers/flattening/boolbv.h>
15+
#include <solvers/miniBDD/miniBDD.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,70 @@ 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 x_bdd = mgr.Var("x");
302+
mini_bddt y_bdd = mgr.Var("y");
303+
mini_bddt final_bdd = x_bdd & y_bdd;
304+
305+
std::ostringstream oss;
306+
mgr.DumpDot(oss);
307+
308+
const std::string dot_string =
309+
"digraph BDD {\n"
310+
"center = true;\n"
311+
"{ rank = same; { node [style=invis]; \"T\" };\n"
312+
" { node [shape=box,fontsize=24]; \"0\"; }\n"
313+
" { node [shape=box,fontsize=24]; \"1\"; }\n"
314+
"}\n"
315+
"\n"
316+
"{ rank=same; { node [shape=plaintext,fontname="
317+
"\"Times Italic\",fontsize=24] \" x \" }; \"2\"; \"4\"; }\n"
318+
"{ rank=same; { node [shape=plaintext,fontname="
319+
"\"Times Italic\",fontsize=24] \" y \" }; \"3\"; }\n"
320+
"\n"
321+
"{ edge [style = invis]; \" x \" -> \" y \" -> \"T\"; }\n"
322+
"\n"
323+
"\"2\" -> \"1\" [style=solid,arrowsize=\".75\"];\n"
324+
"\"2\" -> \"0\" [style=dashed,arrowsize=\".75\"];\n"
325+
"\n"
326+
"\"3\" -> \"1\" [style=solid,arrowsize=\".75\"];\n"
327+
"\"3\" -> \"0\" [style=dashed,arrowsize=\".75\"];\n"
328+
"\n"
329+
"\"4\" -> \"3\" [style=solid,arrowsize=\".75\"];\n"
330+
"\"4\" -> \"0\" [style=dashed,arrowsize=\".75\"];\n"
331+
"\n"
332+
"}\n";
333+
334+
REQUIRE(oss.str() == dot_string);
335+
}
336+
337+
GIVEN("A bdd for (a&b)|!a")
338+
{
339+
symbol_exprt a("a", bool_typet());
340+
symbol_exprt b("b", bool_typet());
341+
342+
or_exprt o(and_exprt(a, b), not_exprt(a));
343+
344+
symbol_tablet symbol_table;
345+
namespacet ns(symbol_table);
346+
347+
{
348+
std::ostringstream oss;
349+
oss << format(o);
350+
REQUIRE(oss.str() == "(a ∧ b) ∨ (¬a)");
351+
}
352+
353+
bdd_exprt t(ns);
354+
t.from_expr(o);
355+
356+
{
357+
std::ostringstream oss;
358+
oss << format(t.as_expr());
359+
REQUIRE(oss.str() == "(¬a) ∨ b");
360+
}
361+
}
294362
}

0 commit comments

Comments
 (0)