Skip to content

Commit

Permalink
Move predicates into the expected testing file
Browse files Browse the repository at this point in the history
  • Loading branch information
SSoelvsten committed Sep 25, 2023
1 parent ec26d5e commit 4f38565
Show file tree
Hide file tree
Showing 3 changed files with 218 additions and 217 deletions.
99 changes: 0 additions & 99 deletions test/adiar/bdd/test_bdd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,104 +234,5 @@ go_bandit([]() {
AssertThat((x0 | x1) != ((x0 & x1) | (~x0 & x1)), Is().True());
});
});

// TODO: Move to 'test_dd_func.cpp'
describe("terminal predicates", [&]() {
describe("is_terminal", [&]() {
it("rejects x0 as a terminal file", [&]() {
AssertThat(is_terminal(x0), Is().False());
});

it("rejects x0 & x1 as a terminal file", [&]() {
AssertThat(is_terminal(x0_and_x1), Is().False());
});

it("accepts a true terminal", [&]() {
AssertThat(is_terminal(terminal_T), Is().True());
});

it("accepts a false terminal", [&]() {
AssertThat(is_terminal(terminal_F), Is().True());
});

it("accepts negation of a false terminal", [&]() {
AssertThat(is_terminal(~ terminal_F), Is().True());
});

it("accepts negation of a true terminal", [&]() {
AssertThat(is_terminal(~ terminal_T), Is().True());
});
});

describe("value_of", [&]() {
it("extracts from a true terminal", [&]() {
AssertThat(value_of(terminal_T), Is().True());
});

it("extracts from a false terminal", [&]() {
AssertThat(value_of(terminal_F), Is().False());
});

it("extracts from a negation of a false terminal", [&]() {
AssertThat(value_of(~ terminal_F), Is().True());
});

it("extracts from a negation of a true terminal", [&]() {
AssertThat(value_of(~ terminal_T), Is().False());
});
});

describe("is_false", [&]() {
it("rejects x0 as a false terminal file", [&]() {
AssertThat(is_false(x0), Is().False());
});

it("rejects x0 & x1 as a false terminal file", [&]() {
AssertThat(is_false(x0_and_x1), Is().False());
});

it("rejects a true terminal", [&]() {
AssertThat(is_false(terminal_T), Is().False());
});

it("accepts a false terminal", [&]() {
AssertThat(is_false(terminal_F), Is().True());
});

it("rejects negation of a false terminal", [&]() {
AssertThat(is_false(~ terminal_F), Is().False());
});

it("accepts negation of a true terminal", [&]() {
AssertThat(is_false(~ terminal_T), Is().True());
});
});

describe("is_true", [&]() {
it("rejects x0 as a true terminal file", [&]() {
AssertThat(is_true(x0), Is().False());
});

it("rejects x0 & x1 as a terminal file", [&]() {
AssertThat(is_true(x0_and_x1), Is().False());
});

it("accepts a true terminal", [&]() {
AssertThat(is_true(terminal_T), Is().True());
});

it("rejects a false terminal", [&]() {
AssertThat(is_true(terminal_F), Is().False());
});

it("accepts negation of a false terminal", [&]() {
AssertThat(is_true(~ terminal_F), Is().True());
});

it("rejects negation of a true terminal", [&]() {
AssertThat(is_true(~ terminal_T), Is().False());
});
});
});
});
});
261 changes: 218 additions & 43 deletions test/adiar/internal/test_dd_func.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,58 @@
#include "../../test.h"

go_bandit([]() {
describe("adiar/internal/util.h", []() {
describe("dd_varprofile(f, cb)", []() {
describe("adiar/internal/dd_func.h", []() {
const ptr_uint64 false_ptr = ptr_uint64(false);
const ptr_uint64 true_ptr = ptr_uint64(true);

shared_levelized_file<node> terminal_F;
{
node_writer writer(terminal_F);
writer << node(false);
}

shared_levelized_file<node> terminal_T;
{
node_writer writer(terminal_T);
writer << node(true);
}

shared_levelized_file<node> x0;
{
node_writer writer(x0);
writer << node(0, node::MAX_ID, false_ptr, true_ptr);
}

shared_levelized_file<node> x42;
{
node_writer writer(x42);
writer << node(42, node::MAX_ID, false_ptr, true_ptr);
}

shared_levelized_file<bdd::node_t> bdd_file;
{
node n3 = node(4, node::MAX_ID, true_ptr, false_ptr);
node n2 = node(3, node::MAX_ID, n3.uid(), false_ptr);
node n1 = node(1, node::MAX_ID, n3.uid(), n2.uid());
node_writer writer(bdd_file);
writer << n3 << n2 << n1;
}

shared_levelized_file<zdd::node_t> zdd_file;
{
node n4 = node(2, node::MAX_ID, true_ptr, true_ptr);
node n3 = node(2, node::MAX_ID-1, false_ptr, true_ptr);
node n2 = node(1, node::MAX_ID, n4.uid(), n4.uid());
node n1 = node(0, node::MAX_ID, n3.uid(), n4.uid());
node_writer writer(zdd_file);
writer << n4 << n3 << n2 << n1;
}

describe("dd_varprofile(f, cb)", [&]() {
// TODO
});

describe("dd_varprofile(f, begin, end)", []() {
shared_levelized_file<node> terminal_F;
{
node_writer writer(terminal_F);
writer << node(false);
}

shared_levelized_file<node> terminal_T;
{
node_writer writer(terminal_T);
writer << node(true);
}

const ptr_uint64 false_ptr = ptr_uint64(false);
const ptr_uint64 true_ptr = ptr_uint64(true);

shared_levelized_file<node> x42;
{
node_writer writer(x42);
writer << node(42, node::MAX_ID, false_ptr, true_ptr);
}

shared_levelized_file<bdd::node_t> bdd_file;
{
node n3 = node(4, node::MAX_ID, true_ptr, false_ptr);
node n2 = node(3, node::MAX_ID, n3.uid(), false_ptr);
node n1 = node(1, node::MAX_ID, n3.uid(), n2.uid());
node_writer writer(bdd_file);
writer << n3 << n2 << n1;
}

shared_levelized_file<zdd::node_t> zdd_file;
{
node n4 = node(2, node::MAX_ID, true_ptr, true_ptr);
node n3 = node(2, node::MAX_ID-1, false_ptr, true_ptr);
node n2 = node(1, node::MAX_ID, n4.uid(), n4.uid());
node n1 = node(0, node::MAX_ID, n3.uid(), n4.uid());
node_writer writer(zdd_file);
writer << n4 << n3 << n2 << n1;
}

describe("dd_varprofile(f, begin, end)", [&]() {
it("does not write anything for BDD false terminal", [&]() {
std::vector<int> out(42, -1);

Expand All @@ -71,6 +77,19 @@ go_bandit([]() {
AssertThat(*it_b, Is().EqualTo(-1));
});

it("returns [0] for a ZDD with one node (label 0)", [&]() {
std::vector<int> out(42, -1);

auto it_b = out.begin();
auto it_e = out.end();

const auto out_it = zdd_varprofile(x0, it_b, it_e);

AssertThat(out_it, Is().EqualTo(it_b+1));
AssertThat(*it_b, Is().EqualTo(0));
AssertThat(*out_it, Is().EqualTo(-1));
});

it("returns [42] for a ZDD with one node (label 42)", [&]() {
std::vector<int> out(42, -1);

Expand Down Expand Up @@ -126,5 +145,161 @@ go_bandit([]() {
AssertThrows(out_of_range, zdd_varprofile(zdd_file, out.begin(), out.end()));
});
});

describe("terminal predicates", [&]() {
describe("is_terminal", [&]() {
it("rejects x0 as a BDD terminal file", [&]() {
AssertThat(is_terminal(bdd(x0)), Is().False());
});

it("rejects x0 as a ZDD terminal file", [&]() {
AssertThat(is_terminal(zdd(x0)), Is().False());
});

it("rejects larger BDD as being a terminal", [&]() {
AssertThat(is_terminal(bdd(bdd_file)), Is().False());
});

it("rejects larger ZDD as being a terminal", [&]() {
AssertThat(is_terminal(zdd(zdd_file)), Is().False());
});

it("accepts a BDD true terminal", [&]() {
AssertThat(is_terminal(bdd(terminal_T)), Is().True());
});

it("accepts a ZDD true terminal", [&]() {
AssertThat(is_terminal(zdd(terminal_T)), Is().True());
});

it("accepts a BDD false terminal", [&]() {
AssertThat(is_terminal(bdd(terminal_F)), Is().True());
});

it("accepts a ZDD false terminal", [&]() {
AssertThat(is_terminal(zdd(terminal_F)), Is().True());
});
});

describe("value_of", [&]() {
it("extracts from a true BDD terminal", [&]() {
AssertThat(value_of(bdd(terminal_T)), Is().True());
});

it("extracts from a negation of a true BDD terminal", [&]() {
AssertThat(value_of(~ bdd(terminal_T)), Is().False());
});

it("extracts from a true ZDD terminal", [&]() {
AssertThat(value_of(zdd(terminal_T)), Is().True());
});

it("extracts from a false BDD terminal", [&]() {
AssertThat(value_of(bdd(terminal_F)), Is().False());
});

it("extracts from a negation of a false BDD terminal", [&]() {
AssertThat(value_of(~ bdd(terminal_F)), Is().True());
});

it("extracts from a false ZDD terminal", [&]() {
AssertThat(value_of(zdd(terminal_F)), Is().False());
});
});

describe("is_false / is_empty", [&]() {
it("rejects x0 [BDD]", [&]() {
AssertThat(is_false(bdd(x0)), Is().False());
});

it("rejects x0 [ZDD]", [&]() {
AssertThat(is_false(zdd(x0)), Is().False());
AssertThat(is_empty(zdd(x0)), Is().False());
});

it("rejects x42 [BDD]", [&]() {
AssertThat(is_false(bdd(x42)), Is().False());
});

it("rejects x42 [ZDD]", [&]() {
AssertThat(is_false(zdd(x42)), Is().False());
AssertThat(is_empty(zdd(x42)), Is().False());
});

it("rejects larger decision diagram [BDD]", [&]() {
AssertThat(is_false(bdd(bdd_file)), Is().False());
});

it("rejects larger decision diagram [ZDD]", [&]() {
AssertThat(is_false(zdd(zdd_file)), Is().False());
AssertThat(is_empty(zdd(zdd_file)), Is().False());
});

it("rejects true terminal [BDD]", [&]() {
AssertThat(is_false(bdd(terminal_T)), Is().False());
});

it("rejects true terminal [ZDD]", [&]() {
AssertThat(is_false(zdd(terminal_T)), Is().False());
AssertThat(is_empty(zdd(terminal_T)), Is().False());
});

it("accepts false terminal [BDD]", [&]() {
AssertThat(is_false(bdd(terminal_F)), Is().True());
});

it("accepts false terminal [ZDD]", [&]() {
AssertThat(is_false(zdd(terminal_F)), Is().True());
AssertThat(is_empty(zdd(terminal_F)), Is().True());
});
});

describe("is_true / is_null", [&]() {
it("rejects x0 [BDD]", [&]() {
AssertThat(is_true(bdd(x0)), Is().False());
});

it("rejects x0 [ZDD]", [&]() {
AssertThat(is_true(zdd(x0)), Is().False());
AssertThat(is_null(zdd(x0)), Is().False());
});

it("rejects x42 [BDD]", [&]() {
AssertThat(is_true(bdd(x42)), Is().False());
});

it("rejects x42 [ZDD]", [&]() {
AssertThat(is_true(zdd(x42)), Is().False());
AssertThat(is_null(zdd(x42)), Is().False());
});

it("rejects larger decision diagram [BDD]", [&]() {
AssertThat(is_true(bdd(bdd_file)), Is().False());
});

it("rejects larger decision diagram [ZDD]", [&]() {
AssertThat(is_true(zdd(zdd_file)), Is().False());
AssertThat(is_null(zdd(zdd_file)), Is().False());
});

it("rejects false terminal [BDD]", [&]() {
AssertThat(is_true(bdd(terminal_F)), Is().False());
});

it("rejects false terminal [ZDD]", [&]() {
AssertThat(is_true(zdd(terminal_F)), Is().False());
AssertThat(is_null(zdd(terminal_F)), Is().False());
});

it("accepts a true terminal [BDD]", [&]() {
AssertThat(is_true(bdd(terminal_T)), Is().True());
});

it("accepts a true terminal [ZDD]", [&]() {
AssertThat(is_true(zdd(terminal_T)), Is().True());
AssertThat(is_null(zdd(terminal_T)), Is().True());
});
});
});
});
});
Loading

0 comments on commit 4f38565

Please sign in to comment.