test/doc/examples/dataset_example68.run-fail.cpp
2019-03-24 17:41:37 +01:00

62 lines
1.6 KiB
C++

// (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_MODULE dataset_example68
#include <boost/test/included/unit_test.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/data/monomorphic.hpp>
#include <sstream>
namespace bdata = boost::unit_test::data;
// Dataset generating a Fibonacci sequence
class fibonacci_dataset {
public:
// the type of the samples is deduced
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<fibonacci_dataset> : boost::mpl::true_ {};
}}}}
// Creating a test-driven dataset, the zip is for checking
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);
}
//]