]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/test/doc/examples/dataset_example68.run-fail.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / test / doc / examples / dataset_example68.run-fail.cpp
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
6 // See http://www.boost.org/libs/test for the library home page.
7
8 //[example_code
9 #define BOOST_TEST_MODULE dataset_example68
10 #include <boost/test/included/unit_test.hpp>
11 #include <boost/test/data/test_case.hpp>
12 #include <boost/test/data/monomorphic.hpp>
13 #include <sstream>
14
15 namespace bdata = boost::unit_test::data;
16
17 // Dataset generating a Fibonacci sequence
18 class fibonacci_dataset {
19 public:
20 // Samples type is int
21 using sample=int;
22 enum { arity = 1 };
23
24 struct iterator {
25
26 iterator() : a(1), b(1) {}
27
28 int operator*() const { return b; }
29 void operator++()
30 {
31 a = a + b;
32 std::swap(a, b);
33 }
34 private:
35 int a;
36 int b; // b is the output
37 };
38
39 fibonacci_dataset() {}
40
41 // size is infinite
42 bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; }
43
44 // iterator
45 iterator begin() const { return iterator(); }
46 };
47
48 namespace boost { namespace unit_test { namespace data { namespace monomorphic {
49 // registering fibonacci_dataset as a proper dataset
50 template <>
51 struct is_dataset<fibonacci_dataset> : boost::mpl::true_ {};
52 }}}}
53
54 // Creating a test-driven dataset
55 BOOST_DATA_TEST_CASE(
56 test1,
57 fibonacci_dataset() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 35, 56 } ),
58 fib_sample, exp)
59 {
60 BOOST_TEST(fib_sample == exp);
61 }
62 //]