dataset_example68.run-fail.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // (C) Copyright Raffi Enficiaud 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //[example_code
  7. #define BOOST_TEST_MODULE dataset_example68
  8. #include <boost/test/included/unit_test.hpp>
  9. #include <boost/test/data/test_case.hpp>
  10. #include <boost/test/data/monomorphic.hpp>
  11. #include <sstream>
  12. namespace bdata = boost::unit_test::data;
  13. // Dataset generating a Fibonacci sequence
  14. class fibonacci_dataset {
  15. public:
  16. // the type of the samples is deduced
  17. enum { arity = 1 };
  18. struct iterator {
  19. iterator() : a(1), b(1) {}
  20. int operator*() const { return b; }
  21. void operator++()
  22. {
  23. a = a + b;
  24. std::swap(a, b);
  25. }
  26. private:
  27. int a;
  28. int b; // b is the output
  29. };
  30. fibonacci_dataset() {}
  31. // size is infinite
  32. bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; }
  33. // iterator
  34. iterator begin() const { return iterator(); }
  35. };
  36. namespace boost { namespace unit_test { namespace data { namespace monomorphic {
  37. // registering fibonacci_dataset as a proper dataset
  38. template <>
  39. struct is_dataset<fibonacci_dataset> : boost::mpl::true_ {};
  40. }}}}
  41. // Creating a test-driven dataset, the zip is for checking
  42. BOOST_DATA_TEST_CASE(
  43. test1,
  44. fibonacci_dataset() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 35, 56 } ),
  45. fib_sample, exp)
  46. {
  47. BOOST_TEST(fib_sample == exp);
  48. }
  49. //]