Lately, I have been working quite hard on writing module tests for CryptoMinisat using GoogleTest. I’d like to share what I’ve learnt and what surprised me most about this exercise.
An example
First of all, let me show how a typical test looks like:
TEST_F(intree, fail_1)
{
s->add_clause_outer(str_to_cl(" 1, 2"));
s->add_clause_outer(str_to_cl("-2, 3"));
s->add_clause_outer(str_to_cl("-2, -3"));
inp->intree_probe();
check_zero_assigned_lits_contains(s, "-2");
}
Here we are checking that intree probing finds that the set of three binary clauses cause a failure and it enqueues “-2” at top level. If one looks at it, it’s a fairly trivial test. It turns out that most are in fact, fairly trivial if the system is set up well. This test’s setup is the following test fixture:
struct intree : public ::testing::Test {
intree()
{
must_inter = false;
s = new Solver(NULL, &must_inter);
s->new_vars(30);
inp = s->intree;
}
~intree()
{
delete s;
}
Solver* s;
InTree* inp;
bool must_inter;
};
Continue reading Testing CryptoMiniSat using GoogleTest →