|
22 | 22 | #include <boost/thread/mutex.hpp> // IWYU pragma: keep |
23 | 23 | #include <boost/thread/lock_guard.hpp> |
24 | 24 | #include <boost/test/unit_test.hpp> // IWYU pragma: keep |
| 25 | +#include <boost/test/data/test_case.hpp> |
| 26 | +#include <boost/test/data/monomorphic.hpp> |
25 | 27 | #include <boost/core/scoped_enum.hpp> |
26 | 28 | #include <boost/foreach.hpp> |
27 | 29 |
|
28 | 30 | #include <cstdlib> |
29 | 31 | #include <set> |
| 32 | +#include <sstream> |
30 | 33 | #include <vector> |
31 | 34 |
|
32 | 35 | BOOST_FORCEINLINE void boost_forceinline_test() |
@@ -199,3 +202,51 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(my_tuple_test, T, test_types_w_tuples) |
199 | 202 | } |
200 | 203 |
|
201 | 204 | 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