#define BOOST_TEST_MODULE dataset_example68 #include #include #include #include namespace bdata = boost::unit_test::data; // Dataset generating a Fibonacci sequence class fibonacci_dataset { public: // Samples type is int using sample=int; enum { arity = 1 }; struct iterator { iterator() : a(1), b(1) {} int operator*() const { return b; } void operator++() { a = a + b; std::swap(a, b); } private: int a; int b; // b is the output }; fibonacci_dataset() {} // size is infinite bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; } // iterator iterator begin() const { return iterator(); } }; 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 // This does compile because the operator^ due to the second operand being in the correct namespace BOOST_DATA_TEST_CASE( test1, fibonacci_dataset() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 35, 56 } ), fib_sample, exp) { BOOST_TEST(fib_sample == exp); } // This does not compile because none of the operands is in the same namespace as the operator^ // It can be made working by declaring the fibonacci dataset within // namespace boost { namespace unit_test { namespace data { namespace monomorphic { // However, that does not sound like a good solution. BOOST_DATA_TEST_CASE( test2, fibonacci_dataset() ^ fibonacci_dataset(), fib_sample, exp) { BOOST_TEST(fib_sample == exp); }