Skip to content

Commit b76e6ca

Browse files
Update boost.cpp
1 parent 8729ad5 commit b76e6ca

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

test/cfg/boost.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
#include <boost/thread/mutex.hpp> // IWYU pragma: keep
2323
#include <boost/thread/lock_guard.hpp>
2424
#include <boost/test/unit_test.hpp> // IWYU pragma: keep
25+
#include <boost/test/data/test_case.hpp>
26+
#include <boost/test/data/monomorphic.hpp>
2527
#include <boost/core/scoped_enum.hpp>
2628
#include <boost/foreach.hpp>
2729

2830
#include <cstdlib>
2931
#include <set>
32+
#include <sstream>
3033
#include <vector>
3134

3235
BOOST_FORCEINLINE void boost_forceinline_test()
@@ -199,3 +202,51 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples)
199202
}
200203

201204
BOOST_AUTO_TEST_SUITE_END()
205+
206+
// https://www.boost.org/doc/libs/latest/libs/test/doc/html/boost_test/tests_organization/test_cases/test_case_generation/datasets.html
207+
namespace bdata = boost::unit_test::data;
208+
209+
// Dataset generating a Fibonacci sequence
210+
class fibonacci_dataset {
211+
public:
212+
// the type of the samples is deduced
213+
static const int arity = 1;
214+
215+
struct iterator {
216+
217+
iterator() : a(1), b(1) {}
218+
219+
int operator*() const { return b; }
220+
void operator++()
221+
{
222+
a = a + b;
223+
std::swap(a, b);
224+
}
225+
private:
226+
int a;
227+
int b; // b is the output
228+
};
229+
230+
fibonacci_dataset() {}
231+
232+
// size is infinite
233+
bdata::size_t size() const { return bdata::BOOST_TEST_DS_INFINITE_SIZE; }
234+
235+
// iterator
236+
iterator begin() const { return iterator(); }
237+
};
238+
239+
namespace boost { namespace unit_test { namespace data { namespace monomorphic {
240+
// registering fibonacci_dataset as a proper dataset
241+
template <>
242+
struct is_dataset<fibonacci_dataset> : boost::mpl::true_ {};
243+
}}}}
244+
245+
// Creating a test-driven dataset, the zip is for checking
246+
BOOST_DATA_TEST_CASE(
247+
test1,
248+
fibonacci_dataset() ^ bdata::make( { 1, 2, 3, 5, 8, 13, 21, 35, 56 } ),
249+
fib_sample, exp)
250+
{
251+
BOOST_TEST(fib_sample == exp);
252+
}

0 commit comments

Comments
 (0)