// (C) Copyright Raffi Enficiaud 2014. // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // See http://www.boost.org/libs/test for the library home page. //[example_code #define BOOST_TEST_MAIN #include #include #include #include namespace bdata = boost::unit_test::data; // Dataset generating a Fibonacci sequence class fibonacci_dataset : public bdata::monomorphic::dataset { public: // Samples type is int typedef int data_type; enum { arity = 1 }; private: typedef bdata::monomorphic::dataset base; struct iterator : base::iterator { typedef typename bdata::monomorphic::traits::ref_type ref_type; int a; int b; // b is the output iterator() : a(0), b(0) {} ref_type operator*() { return b; } virtual void operator++() { a = a + b; std::swap(a, b); if(!b) b = 1; } }; public: fibonacci_dataset() {} // size is infinite bdata::size_t size() const { return bdata::size_t(true); } // iterator virtual iter_ptr begin() const { return boost::make_shared(); } }; namespace boost { namespace unit_test { namespace data { namespace monomorphic { // registering fibonacci_dataset as a proper dataset template <> struct is_dataset : boost::mpl::true_ {}; }}}} // Creating a test-driven dataset BOOST_DATA_TEST_CASE( test_case_snippet_1, fibonacci_dataset() ^ bdata::xrange(10), fib_sample, index) { std::cout << "test 1: " << fib_sample << std::endl; BOOST_CHECK(fib_sample <= 13); } //]