Skip to content

Commit

Permalink
Improve tests stability and run tests in random order
Browse files Browse the repository at this point in the history
ifsmirnov committed Feb 5, 2018
1 parent daf2263 commit 16ebe49
Showing 3 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ CXX = g++-5
.PHONY: clean run

run: main
./main
./main --random=1

lib.o: ../jngen.h ../lib.cpp
$(CXX) $(CXXFLAGS) -UJNGEN_DECLARE_ONLY ../lib.cpp -c -o lib.o
4 changes: 4 additions & 0 deletions tests/graph.cpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
BOOST_AUTO_TEST_SUITE(graph)

BOOST_AUTO_TEST_CASE(output) {
setMod().reset();

Graph g;
g.addEdge(0, 2);
g.addEdge(1, 3);
@@ -20,6 +22,8 @@ BOOST_AUTO_TEST_CASE(output) {
}

BOOST_AUTO_TEST_CASE(weights_and_labelling) {
setMod().reset();

rnd.seed(123);

Graph g = Graph::random(10, 20);
15 changes: 12 additions & 3 deletions tests/tree.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,8 @@ void checkEquals(const jngen::Tree& t1, const jngen::Tree& t2) {
}

BOOST_AUTO_TEST_CASE(manual_construction) {
setMod().reset();

Tree t;

BOOST_CHECK_EQUAL(t.n(), 1);
@@ -102,6 +104,9 @@ int findDiameter(
* of the resulting trees such as diameter.
*/
BOOST_AUTO_TEST_CASE(generators) {
setMod().reset();
rnd.seed(12345);

std::vector<int> centers, dist;

auto b = Tree::bamboo(10);
@@ -127,13 +132,16 @@ BOOST_AUTO_TEST_CASE(generators) {
BOOST_CHECK_EQUAL(findDiameter(s, centers, dist), 2);
BOOST_CHECK_EQUAL(centers[0], 0);

// probability of failure < 1e-5
auto c = Tree::caterpillar(100, 10);
BOOST_CHECK_EQUAL(findDiameter(c, centers, dist), 11);

c = Tree::caterpillar(1005, 1000);
BOOST_CHECK_EQUAL(findDiameter(c, centers, dist), 999);
// probability of failure < 1e-3
c = Tree::caterpillar(8004, 8000);
BOOST_CHECK_EQUAL(findDiameter(c, centers, dist), 7999);

auto t = Tree::randomPrim(150, 1000);
// probability of failure unknown, but very low
auto t = Tree::randomPrim(150, 15000);
BOOST_CHECK_EQUAL(t, Tree::bamboo(150));
}

@@ -223,6 +231,7 @@ BOOST_AUTO_TEST_CASE(check_glue) {

BOOST_AUTO_TEST_CASE(print_parents) {
rnd.seed(123);
setMod().reset();

std::ostringstream ss;

0 comments on commit 16ebe49

Please sign in to comment.