Skip to content

Commit

Permalink
speed up tests build
Browse files Browse the repository at this point in the history
  • Loading branch information
ifsmirnov committed Jun 2, 2017
1 parent febd30a commit 1ba49b6
Show file tree
Hide file tree
Showing 14 changed files with 315 additions and 152 deletions.
341 changes: 212 additions & 129 deletions jngen.h

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions lib.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "jngen.h"
23 changes: 23 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
CXXFLAGS = -O2 -Wall -Wextra -Werror -std=c++11
CXXFLAGS += -DJNGEN_DECLARE_ONLY
LDFLAGS += -lboost_system -lboost_unit_test_framework

CXX = g++-4.9

.PHONY: clean run

run: main
./main

../lib.o: ../jngen.h ../lib.cpp
cd .. && $(CXX) $(CXXFLAGS) -UJNGEN_DECLARE_ONLY lib.cpp -c

%.o: %.cpp ../jngen.h
$(CXX) $(CXXFLAGS) $< -c

main: $(subst .cpp,.o,$(wildcard *.cpp)) ../lib.o
$(info $^)
$(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@

clean:
rm -rf -- main *.o
8 changes: 6 additions & 2 deletions tests/array.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <algorithm>
#include <utility>

BOOST_AUTO_TEST_SUITE(array)

BOOST_AUTO_TEST_CASE(basics) {
Array a, b;

Expand Down Expand Up @@ -135,3 +137,5 @@ BOOST_AUTO_TEST_CASE(random_generation) {

BOOST_CHECK_EQUAL(b.sorted(), c.sorted().uniqued());
}

BOOST_AUTO_TEST_SUITE_END()
8 changes: 6 additions & 2 deletions tests/dsu.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

using jngen::Dsu;

BOOST_AUTO_TEST_SUITE(generic_graph)

BOOST_AUTO_TEST_CASE(dsu) {
Dsu d;

Expand All @@ -21,3 +23,5 @@ BOOST_AUTO_TEST_CASE(dsu) {

BOOST_CHECK(!d.unite(0, 0));
}

BOOST_AUTO_TEST_SUITE_END()
10 changes: 7 additions & 3 deletions tests/generic_graph.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <sstream>

using jngen::GenericGraph;

#include <sstream>
BOOST_AUTO_TEST_SUITE(generic_graph)

BOOST_AUTO_TEST_CASE(basics) {
GenericGraph gg;
Expand Down Expand Up @@ -33,3 +35,5 @@ BOOST_AUTO_TEST_CASE(basics) {
g2.addEdge(1, 2);
BOOST_CHECK(!(gg == g2));
}

BOOST_AUTO_TEST_SUITE_END()
8 changes: 6 additions & 2 deletions tests/graph.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

BOOST_AUTO_TEST_SUITE(graph)

BOOST_AUTO_TEST_CASE(output) {
Graph g;
g.addEdge(0, 2);
Expand Down Expand Up @@ -63,3 +65,5 @@ BOOST_AUTO_TEST_CASE(weights_and_labelling) {

BOOST_CHECK_EQUAL(count, 1);
}

BOOST_AUTO_TEST_SUITE_END()
3 changes: 3 additions & 0 deletions tests/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#define BOOST_TEST_DYN_LINK
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
7 changes: 5 additions & 2 deletions tests/math.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <utility>

BOOST_AUTO_TEST_SUITE(math)

BOOST_AUTO_TEST_CASE(primes) {
rnd.seed(123);

Expand Down Expand Up @@ -46,3 +48,4 @@ BOOST_AUTO_TEST_CASE(primes) {
BOOST_CHECK_THROW(rndm.randomPrime(14, 16), jngen::Exception);
}

BOOST_AUTO_TEST_SUITE_END()
10 changes: 6 additions & 4 deletions tests/printers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <map>
Expand All @@ -8,6 +8,8 @@
#include <utility>
#include <vector>

BOOST_AUTO_TEST_SUITE(printers)

template<typename T>
void checkOutput(const T& t, const std::string& s) {
std::ostringstream ss;
Expand All @@ -26,8 +28,6 @@ BOOST_AUTO_TEST_CASE(vector_depth) {
std::vector<std::vector<std::vector<Pair>>>>::value == 3);
}

#undef COMMAdjdji

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

Expand Down Expand Up @@ -58,3 +58,5 @@ BOOST_AUTO_TEST_CASE(set_map) {
{"one", 1}, {"two", 2}, {"three", 3}},
"one 1\nthree 3\ntwo 2");
}

BOOST_AUTO_TEST_SUITE_END()
8 changes: 6 additions & 2 deletions tests/random.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <algorithm>
#include <string>
#include <vector>

BOOST_AUTO_TEST_SUITE(random_suite)

BOOST_AUTO_TEST_CASE(basic_methods) {
rnd.seed(123);

Expand Down Expand Up @@ -161,3 +163,5 @@ BOOST_AUTO_TEST_CASE(signed_bounds) {
rnd.wnext((long long)(-6e18), (long long)(6e18), 10);
rnd.wnext((long long)(-6e18), (long long)(6e18), -4);
}

BOOST_AUTO_TEST_SUITE_END()
8 changes: 6 additions & 2 deletions tests/repr.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <sstream>
#include <utility>
#include <vector>

BOOST_AUTO_TEST_SUITE(repr_suite)

template<typename T>
void checkOutput(const T& t, const std::string& s) {
std::ostringstream ss;
Expand Down Expand Up @@ -90,3 +92,5 @@ BOOST_AUTO_TEST_CASE(external_repr) {
checkOutput(repr(y), "0.123456 31415");
checkOutput(repr(y).add1(), "0.123456 31416");
}

BOOST_AUTO_TEST_SUITE_END()
20 changes: 20 additions & 0 deletions tests/rnds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <algorithm>
#include <utility>

BOOST_AUTO_TEST_SUITE(rnds_suite)

BOOST_AUTO_TEST_CASE(basics) {
rnd.seed(123);

BOOST_CHECK_EQUAL(rnds.abacaba(10), "abacabadab");
BOOST_CHECK_EQUAL(rnds.abacaba(10, 'A'), "ABACABADAB");

BOOST_CHECK_EQUAL(rnds.thueMorse(10), "abbabaabba");
BOOST_CHECK_EQUAL(rnds.thueMorse(10, 'q', 'w'), "qwwqwqqwwq");
}

BOOST_AUTO_TEST_SUITE_END()
12 changes: 8 additions & 4 deletions tests/tree.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#define BOOST_TEST_MAIN
#include <boost/test/included/unit_test.hpp>
#define BOOST_TEST_DYN_LINK
#include <boost/test/unit_test.hpp>
#include "../jngen.h"

#include <algorithm>
#include <set>
#include <sstream>
#include <utility>

BOOST_AUTO_TEST_SUITE(tree)

BOOST_AUTO_TEST_CASE(manual_construction) {
Tree t;

Expand Down Expand Up @@ -118,10 +120,10 @@ BOOST_AUTO_TEST_CASE(generators) {
BOOST_CHECK_EQUAL(findDiameter(s, centers, dist), 2);
BOOST_CHECK_EQUAL(centers[0], 0);

auto c = Tree::caterpillar(10, 100);
auto c = Tree::caterpillar(100, 10);
BOOST_CHECK_EQUAL(findDiameter(c, centers, dist), 11);

c = Tree::caterpillar(1000, 1005);
c = Tree::caterpillar(1005, 1000);
BOOST_CHECK_EQUAL(findDiameter(c, centers, dist), 999);

auto t = Tree::random(150, 1000);
Expand Down Expand Up @@ -213,3 +215,5 @@ BOOST_AUTO_TEST_CASE(check_glue) {
}

// TODO: add tests to check random generators exactly

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 1ba49b6

Please sign in to comment.