From 1ba49b61d16ad88a0fbdefa2458631800f1d55be Mon Sep 17 00:00:00 2001 From: Ivan Smirnov Date: Fri, 2 Jun 2017 16:46:27 -0700 Subject: [PATCH] speed up tests build --- jngen.h | 341 +++++++++++++++++++++++++--------------- lib.cpp | 1 + tests/Makefile | 23 +++ tests/array.cpp | 8 +- tests/dsu.cpp | 8 +- tests/generic_graph.cpp | 10 +- tests/graph.cpp | 8 +- tests/main.cpp | 3 + tests/math.cpp | 7 +- tests/printers.cpp | 10 +- tests/random.cpp | 8 +- tests/repr.cpp | 8 +- tests/rnds.cpp | 20 +++ tests/tree.cpp | 12 +- 14 files changed, 315 insertions(+), 152 deletions(-) create mode 100644 lib.cpp create mode 100644 tests/Makefile create mode 100644 tests/main.cpp create mode 100644 tests/rnds.cpp diff --git a/jngen.h b/jngen.h index 1db1eca..2ecf599 100644 --- a/jngen.h +++ b/jngen.h @@ -145,11 +145,14 @@ using jngen::ContextTimer; using jngen::distribution; #include +#include +#include namespace jngen { namespace drawing { enum class Color { + None, White, Black, Red, @@ -159,6 +162,13 @@ enum class Color { LightGrey }; +struct DrawingEngineState { + double width; + Color stroke; + Color fill; + double opacity; +}; + class DrawingEngine { public: DrawingEngine() {} @@ -167,14 +177,31 @@ class DrawingEngine { virtual void drawPoint(double x, double y) = 0; virtual void drawCircle(double x, double y, double r) = 0; virtual void drawSegment(double x1, double y1, double x2, double y2) = 0; + virtual void drawPolygon( + const std::vector>& vertices) = 0; virtual void drawText( double x, double y, const std::string& s) = 0; virtual void setWidth(double width) = 0; - virtual void setColor(Color color) = 0; + virtual void setStroke(Color color) = 0; + virtual void setFill(Color color) = 0; + virtual void setOpacity(double opacity) = 0; - virtual Color color() const = 0; virtual double width() const = 0; + virtual Color stroke() const = 0; + virtual Color fill() const = 0; + virtual double opacity() const = 0; + + DrawingEngineState saveState() { + return { width(), stroke(), fill(), opacity() }; + } + + void restoreState(const DrawingEngineState& state) { + setWidth(state.width); + setStroke(state.stroke); + setFill(state.fill); + setOpacity(state.opacity); + } }; }} // namespace jngen::drawing @@ -196,14 +223,20 @@ class SvgEngine : public DrawingEngine { virtual void drawCircle(double x, double y, double r) override; virtual void drawSegment( double x1, double y1, double x2, double y2) override; + virtual void drawPolygon( + const std::vector>& vertices) override; virtual void drawText( double x, double y, const std::string& s) override; virtual void setWidth(double width) override; - virtual void setColor(Color color) override; + virtual void setStroke(Color color) override; + virtual void setFill(Color color) override; + virtual void setOpacity(double opacity) override; - virtual Color color() const override { return color_; } virtual double width() const override { return width_; } + virtual Color stroke() const override { return strokeColor_; } + virtual Color fill() const override { return fillColor_; } + virtual double opacity() const override { return opacity_; } std::string serialize() const; @@ -214,16 +247,21 @@ class SvgEngine : public DrawingEngine { double lerpY(double y) const; double scaleSize(double size) const; + std::string getStyle() const; + std::ostringstream output_; double width_; - Color color_; + Color strokeColor_; + Color fillColor_; + double opacity_; double x1_, y1_, x2_, y2_; // borders }; inline const char* SvgEngine::colorToString(Color color) { switch (color) { + case Color::None: return "none"; case Color::White: return "white"; case Color::Black: return "black"; case Color::Red: return "red"; @@ -231,7 +269,7 @@ inline const char* SvgEngine::colorToString(Color color) { case Color::Blue: return "blue"; case Color::Grey: return "grey"; case Color::LightGrey: return "lightgrey"; - default: return "black"; + default: return "none"; } } @@ -264,7 +302,9 @@ double lerp(double x, double l, double r, double L, double R) { SvgEngine::SvgEngine(double x1, double y1, double x2, double y2) : width_(1.0), - color_(Color::Black), + strokeColor_(Color::Black), + fillColor_(Color::Black), + opacity_(1.0), x1_(x1), y1_(y1), x2_(x2), @@ -277,8 +317,8 @@ void SvgEngine::drawPoint(double x, double y) { double w = width_ * WIDTH_SCALE * 1.5; sprintf( buf, - "", - x, y, w, colorToString(color_) + "", + x, y, w, colorToString(strokeColor_), opacity_ ); output_ << buf << "\n"; } @@ -289,12 +329,22 @@ void SvgEngine::drawCircle(double x, double y, double r) { r = scaleSize(r); sprintf( buf, - "", - x, y, r, colorToString(color_) + "", + x, y, r, getStyle().c_str() ); output_ << buf << "\n"; } +void SvgEngine::drawPolygon( + const std::vector>& points) +{ + output_ << "\n"; +} + void SvgEngine::drawSegment( double x1, double y1, double x2, double y2) { @@ -312,8 +362,8 @@ void SvgEngine::drawSegment( } sprintf( buf, - "", - x1, y1, x2, y2, colorToString(color_), width_ * WIDTH_SCALE + "", + x1, y1, x2, y2, getStyle().c_str() ); output_ << buf << "\n"; } @@ -335,8 +385,16 @@ void SvgEngine::setWidth(double width) { width_ = width; } -void SvgEngine::setColor(Color color) { - color_ = color; +void SvgEngine::setStroke(Color color) { + strokeColor_ = color; +} + +void SvgEngine::setFill(Color color) { + fillColor_ = color; +} + +void SvgEngine::setOpacity(double opacity) { + opacity_ = opacity; } std::string SvgEngine::serialize() const { @@ -368,6 +426,19 @@ double SvgEngine::scaleSize(double size) const { return size * CANVAS_SIZE / (x2_ - x1_); } +std::string SvgEngine::getStyle() const { + static char buf[1024]; + sprintf( + buf, + "stroke-width:%f;stroke:%s;fill:%s;opacity:%f", + width_ * WIDTH_SCALE, + colorToString(strokeColor_), + colorToString(fillColor_), + opacity_ + ); + return buf; +} + }} // namespace jngen::drawing #undef JNGEN_INCLUDE_SVG_ENGINE_INL_H @@ -389,6 +460,8 @@ namespace drawing { class Drawer { public: + Drawer(); + template void point(const P& p); @@ -404,9 +477,16 @@ class Drawer { void setWidth(double width); void setColor(Color color); - void setColor(const std::string& desc); + void setStroke(Color color); + void setStroke(const std::string& desc); + + void setFill(Color color); + void setFill(const std::string& desc); + + void setOpacity(double opacity); + void dumpSvg(const std::string& filename); private: @@ -416,17 +496,18 @@ class Drawer { Point(double x, double y) : x(x), y(y) {} }; - struct DrawRequest; + typedef std::function DrawRequest; typedef std::pair Bbox; + static Color colorByName(const std::string& name); + static Bbox emptyBbox(); static Bbox unite(const Bbox& lhs, const Bbox& rhs); static Bbox bbox(const Point& p); static Bbox bbox(const std::pair& circle); - static Bbox bbox(const std::pair& segment); Bbox getBbox() const; @@ -435,91 +516,64 @@ class Drawer { void drawAll(); void drawGrid(const Bbox& bbox); - std::vector points_; - std::vector> circles_; - std::vector> segments_; - std::vector requests_; DrawingEngine* engine_; + Bbox bbox_; int requestId_ = 0; }; -struct Drawer::DrawRequest { - enum class Type { - Point, Circle, Segment, Color, Width - }; - - Type type; - union { - int id; - double width; - Color color; - }; - - static DrawRequest fromObject(Type type, int id) { - DrawRequest request; - request.type = type; - request.id = id; - return request; - } - - static DrawRequest fromWidth(double width) { - DrawRequest request; - request.type = Type::Width; - request.width = width; - return request; - } - - static DrawRequest fromColor(Color color) { - DrawRequest request; - request.type = Type::Color; - request.color = color; - return request; - } -}; - template void Drawer::point(const P& p) { - requests_.push_back(DrawRequest::fromObject( - DrawRequest::Type::Point, points_.size())); - points_.emplace_back(Point(p.x, p.y)); + bbox_ = unite(bbox_ , bbox(Point(p.x, p.y))); + requests_.push_back([p](DrawingEngine* engine) { + engine->drawPoint(p.x, p.y); + }); } template void Drawer::circle(const P& p, double radius) { - requests_.push_back(DrawRequest::fromObject( - DrawRequest::Type::Circle, circles_.size())); - circles_.emplace_back(Point(p.x, p.y), radius); + bbox_ = unite(bbox_ , bbox({Point(p.x, p.y), radius})); + requests_.push_back([p, radius](DrawingEngine* engine) { + engine->drawCircle(p.x, p.y, radius); + }); } template void Drawer::segment(const P& p1, const P& p2) { - requests_.push_back(DrawRequest::fromObject( - DrawRequest::Type::Segment, segments_.size())); - segments_.emplace_back(Point(p1.x, p1.y), Point(p2.x, p2.y)); + bbox_ = unite(bbox_ , bbox(Point(p1.x, p1.y))); + bbox_ = unite(bbox_ , bbox(Point(p2.x, p2.y))); + requests_.push_back([p1, p2](DrawingEngine* engine) { + engine->drawSegment(p1.x, p1.y, p2.x, p2.y); + }); } template void Drawer::polygon(const std::vector

& points) { - for (size_t i = 0; i + 1 < points.size(); ++i) { - segment(points[i], points[i+1]); + for (const auto& p: points) { + bbox_ = unite(bbox_, bbox(Point(p.x, p.y))); } - segment(points.back(), points.front()); + + requests_.push_back([points](DrawingEngine* engine) { + std::vector> enginePoints; + for (const auto& p: points) { + enginePoints.emplace_back(p.x, p.y); + } + engine->drawPolygon(enginePoints); + }); } #ifndef JNGEN_DECLARE_ONLY -void Drawer::setWidth(double width) { - requests_.push_back(DrawRequest::fromWidth(width)); +Drawer::Drawer() : bbox_(emptyBbox()) { + setFill("none"); + setStroke("black"); } -void Drawer::setColor(Color color) { - requests_.push_back(DrawRequest::fromColor(color)); -} - -void Drawer::setColor(const std::string& desc) { +Color Drawer::colorByName(const std::string& name) { const static std::map colors = { + {"", Color::None}, + {"none", Color::None}, {"white", Color::White}, {"black", Color::Black}, {"red", Color::Red}, @@ -531,11 +585,52 @@ void Drawer::setColor(const std::string& desc) { {"lightgray", Color::LightGrey} }; - if (!colors.count(desc)) { - throw std::logic_error("Color `" + desc + "' is not supported"); + if (!colors.count(name)) { + throw std::logic_error("Color `" + name+ "' is not supported"); } - setColor(colors.at(desc)); + return colors.at(name); +} + +void Drawer::setWidth(double width) { + requests_.push_back([width](DrawingEngine* engine) { + engine->setWidth(width); + }); +} + +void Drawer::setColor(Color color) { + setStroke(color); + setFill(color); +} + +void Drawer::setStroke(Color color) { + requests_.push_back([color](DrawingEngine* engine) { + engine->setStroke(color); + }); +} + +void Drawer::setFill(Color color) { + requests_.push_back([color](DrawingEngine* engine) { + engine->setFill(color); + }); +} + +void Drawer::setColor(const std::string& desc) { + setColor(colorByName(desc)); +} + +void Drawer::setStroke(const std::string& desc) { + setStroke(colorByName(desc)); +} + +void Drawer::setFill(const std::string& desc) { + setFill(colorByName(desc)); +} + +void Drawer::setOpacity(double opacity) { + requests_.push_back([opacity](DrawingEngine* engine) { + engine->setOpacity(opacity); + }); } Drawer::Bbox Drawer::emptyBbox() { @@ -568,24 +663,6 @@ Drawer::Bbox Drawer::bbox(const std::pair& circle) { }; } -Drawer::Bbox Drawer::bbox(const std::pair& segment) { - return unite(bbox(segment.first), bbox(segment.second)); -} - -Drawer::Bbox Drawer::getBbox() const { - Bbox result = emptyBbox(); - for (const auto& t: points_) { - result = unite(result, bbox(t)); - } - for (const auto& t: circles_) { - result = unite(result, bbox(t)); - } - for (const auto& t: segments_) { - result = unite(result, bbox(t)); - } - return result; -} - /* Given a bbox of points, returns a bbox with following properties: - at least 5% margin at each side is blank @@ -653,29 +730,7 @@ Drawer::Bbox Drawer::viewportByBbox(const Bbox& bbox) { void Drawer::drawAll() { for (const auto& request: requests_) { - switch (request.type) { - case DrawRequest::Type::Point: { - const auto& t = points_[request.id]; - engine_->drawPoint(t.x, t.y); - break; - } - case DrawRequest::Type::Circle: { - const auto& t = circles_[request.id]; - engine_->drawCircle(t.first.x, t.first.y, t.second); - break; - } - case DrawRequest::Type::Segment: { - const auto& t = segments_[request.id]; - engine_->drawSegment(t.first.x, t.first.y, t.second.x, t.second.y); - break; - } - case DrawRequest::Type::Width: - engine_->setWidth(request.width); - break; - case DrawRequest::Type::Color: - engine_->setColor(request.color); - break; - } + request(engine_); } } @@ -687,8 +742,7 @@ void Drawer::drawGrid(const Bbox& bbox) { constexpr static int MAX_SPREAD_TO_DRAW_ALL_TICKS = 13; constexpr static double TEXT_OFFSET_RATIO = 0.01; - Color savedColor = engine_->color(); - double savedWidth = engine_->width(); + auto savedState = engine_->saveState(); int step = 5; double spread = std::min( @@ -703,7 +757,7 @@ void Drawer::drawGrid(const Bbox& bbox) { } engine_->setWidth(0.5); - engine_->setColor(Color::LightGrey); + engine_->setStroke(Color::LightGrey); double smallStep = 1.0 * step / SMALL_IN_BIG; @@ -728,7 +782,7 @@ void Drawer::drawGrid(const Bbox& bbox) { } engine_->setWidth(0.75); - engine_->setColor(Color::Grey); + engine_->setStroke(Color::Grey); for ( double tick = std::ceil(bbox.first.x / step) * step; @@ -784,16 +838,15 @@ void Drawer::drawGrid(const Bbox& bbox) { step = 1; } - engine_->setColor(savedColor); - engine_->setWidth(savedWidth); + engine_->restoreState(savedState); } void Drawer::dumpSvg(const std::string& filename) { - if (points_.empty() && circles_.empty() && segments_.empty()) { + if (requests_.empty()) { return; } - auto bbox = getBbox(); + auto bbox = bbox_; auto viewport = viewportByBbox(bbox); std::unique_ptr svgEngine(new SvgEngine( viewport.first.x, viewport.first.y, @@ -2086,7 +2139,7 @@ JNGEN_DEFINE_FUNCTION_CHECKER( JNGEN_DEFINE_FUNCTION_CHECKER( Plus, - std::declval() + 1 + T(std::declval() + 1) ) JNGEN_DEFINE_FUNCTION_CHECKER( @@ -3343,6 +3396,34 @@ class GeometryRandom { return res.subseq(Array::id(res.size()).choice(n).sort()); } + + static TArray pointsInCommonPosition( + int n, long long X, long long Y) { + TArray res; + while (static_cast(res.size()) != n) { + Point p = point(X, Y); + bool ok = true; + for (size_t i = 0; i < res.size(); ++i) { + if (p == res[i]) { + ok = false; + break; + } + for (size_t j = 0; j < i; ++j) { + if ((res[i] - res[j]) % (res[i] - p) == 0) { + ok = false; + break; + } + } + if (!ok) { + break; + } + } + if (ok) { + res.push_back(p); + } + } + return res; + } }; JNGEN_EXTERN GeometryRandom rndg; @@ -4481,6 +4562,7 @@ void GenericGraph::permuteEdges(const Array& order) { } void GenericGraph::normalizeEdges() { +#ifndef JNGEN_NO_NORMALIZE_EDGES ENSURE( vertexLabel_ == Array::id(n()), "Can call normalizeEdges() only on newly created graph"); @@ -4499,6 +4581,7 @@ void GenericGraph::normalizeEdges() { }); permuteEdges(order); +#endif // JNGEN_NO_NORMALIZE_EDGES } void GenericGraph::addEdge(int u, int v, const Weight& w) { @@ -4600,7 +4683,7 @@ bool GenericGraph::operator<=(const GenericGraph& other) const { } bool GenericGraph::operator>=(const GenericGraph& other) const { - return compareTo(other) == -1; + return compareTo(other) != -1; } int GenericGraph::compareTo(const GenericGraph& other) const { diff --git a/lib.cpp b/lib.cpp new file mode 100644 index 0000000..b113b23 --- /dev/null +++ b/lib.cpp @@ -0,0 +1 @@ +#include "jngen.h" diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..0cbdb2b --- /dev/null +++ b/tests/Makefile @@ -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 diff --git a/tests/array.cpp b/tests/array.cpp index 0e7b3ea..e637d47 100644 --- a/tests/array.cpp +++ b/tests/array.cpp @@ -1,10 +1,12 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include #include +BOOST_AUTO_TEST_SUITE(array) + BOOST_AUTO_TEST_CASE(basics) { Array a, b; @@ -135,3 +137,5 @@ BOOST_AUTO_TEST_CASE(random_generation) { BOOST_CHECK_EQUAL(b.sorted(), c.sorted().uniqued()); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/dsu.cpp b/tests/dsu.cpp index 9987e96..699b1a8 100644 --- a/tests/dsu.cpp +++ b/tests/dsu.cpp @@ -1,9 +1,11 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" using jngen::Dsu; +BOOST_AUTO_TEST_SUITE(generic_graph) + BOOST_AUTO_TEST_CASE(dsu) { Dsu d; @@ -21,3 +23,5 @@ BOOST_AUTO_TEST_CASE(dsu) { BOOST_CHECK(!d.unite(0, 0)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/generic_graph.cpp b/tests/generic_graph.cpp index 40d43aa..9157720 100644 --- a/tests/generic_graph.cpp +++ b/tests/generic_graph.cpp @@ -1,10 +1,12 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" +#include + using jngen::GenericGraph; -#include +BOOST_AUTO_TEST_SUITE(generic_graph) BOOST_AUTO_TEST_CASE(basics) { GenericGraph gg; @@ -33,3 +35,5 @@ BOOST_AUTO_TEST_CASE(basics) { g2.addEdge(1, 2); BOOST_CHECK(!(gg == g2)); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/graph.cpp b/tests/graph.cpp index 665d2c0..1c583c3 100644 --- a/tests/graph.cpp +++ b/tests/graph.cpp @@ -1,7 +1,9 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" +BOOST_AUTO_TEST_SUITE(graph) + BOOST_AUTO_TEST_CASE(output) { Graph g; g.addEdge(0, 2); @@ -63,3 +65,5 @@ BOOST_AUTO_TEST_CASE(weights_and_labelling) { BOOST_CHECK_EQUAL(count, 1); } + +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 0000000..0b47303 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,3 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MAIN +#include diff --git a/tests/math.cpp b/tests/math.cpp index e1f52f8..a39b7de 100644 --- a/tests/math.cpp +++ b/tests/math.cpp @@ -1,9 +1,11 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include +BOOST_AUTO_TEST_SUITE(math) + BOOST_AUTO_TEST_CASE(primes) { rnd.seed(123); @@ -46,3 +48,4 @@ BOOST_AUTO_TEST_CASE(primes) { BOOST_CHECK_THROW(rndm.randomPrime(14, 16), jngen::Exception); } +BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/printers.cpp b/tests/printers.cpp index 9a64eeb..1643d0f 100644 --- a/tests/printers.cpp +++ b/tests/printers.cpp @@ -1,5 +1,5 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include @@ -8,6 +8,8 @@ #include #include +BOOST_AUTO_TEST_SUITE(printers) + template void checkOutput(const T& t, const std::string& s) { std::ostringstream ss; @@ -26,8 +28,6 @@ BOOST_AUTO_TEST_CASE(vector_depth) { std::vector>>>::value == 3); } -#undef COMMAdjdji - BOOST_AUTO_TEST_CASE(trivial) { setMod().reset(); @@ -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() diff --git a/tests/random.cpp b/tests/random.cpp index 26fbf75..757e321 100644 --- a/tests/random.cpp +++ b/tests/random.cpp @@ -1,11 +1,13 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include #include #include +BOOST_AUTO_TEST_SUITE(random_suite) + BOOST_AUTO_TEST_CASE(basic_methods) { rnd.seed(123); @@ -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() diff --git a/tests/repr.cpp b/tests/repr.cpp index 6deac38..64c0c2a 100644 --- a/tests/repr.cpp +++ b/tests/repr.cpp @@ -1,11 +1,13 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include #include #include +BOOST_AUTO_TEST_SUITE(repr_suite) + template void checkOutput(const T& t, const std::string& s) { std::ostringstream ss; @@ -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() diff --git a/tests/rnds.cpp b/tests/rnds.cpp new file mode 100644 index 0000000..ef1c33c --- /dev/null +++ b/tests/rnds.cpp @@ -0,0 +1,20 @@ +#define BOOST_TEST_DYN_LINK +#include +#include "../jngen.h" + +#include +#include + +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() diff --git a/tests/tree.cpp b/tests/tree.cpp index c5ca5c2..56b7192 100644 --- a/tests/tree.cpp +++ b/tests/tree.cpp @@ -1,5 +1,5 @@ -#define BOOST_TEST_MAIN -#include +#define BOOST_TEST_DYN_LINK +#include #include "../jngen.h" #include @@ -7,6 +7,8 @@ #include #include +BOOST_AUTO_TEST_SUITE(tree) + BOOST_AUTO_TEST_CASE(manual_construction) { Tree t; @@ -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); @@ -213,3 +215,5 @@ BOOST_AUTO_TEST_CASE(check_glue) { } // TODO: add tests to check random generators exactly + +BOOST_AUTO_TEST_SUITE_END()