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 example67
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 // Generates a Fibonacci sequence
fibonacci()18 std::vector<float> fibonacci() {
19   std::vector<float> ret(8);
20   ret[0] = 0;
21   ret[1] = 1;
22 
23   for(std::size_t s(2); s < ret.size(); s++)
24   {
25     ret[s] = ret[s-1] + ret[s-2];
26   }
27   return ret;
28 }
29 
BOOST_DATA_TEST_CASE(test1,bdata::make (fibonacci ()),array_element)30 BOOST_DATA_TEST_CASE(
31   test1,
32   bdata::make(fibonacci()),
33   array_element)
34 {
35   std::cout << "test 1: "
36     << array_element
37     << std::endl;
38   BOOST_TEST(array_element <= 13);
39 }
40 
41 
42 // Generates a map from a vector
vect_2_str(std::vector<float> v)43 std::map<std::string, float> vect_2_str(std::vector<float> v)
44 {
45   std::map<std::string, float> out;
46   for(std::size_t s(0); s < v.size(); s++)
47   {
48     std::ostringstream o;
49     o << v[s];
50     out[o.str()] = v[s];
51   }
52   return out;
53 }
54 
55 typedef std::pair<const std::string, float> pair_map_t;
56 BOOST_TEST_DONT_PRINT_LOG_VALUE( pair_map_t )
57 
BOOST_DATA_TEST_CASE(test2,bdata::make (vect_2_str (fibonacci ())),array_element)58 BOOST_DATA_TEST_CASE(
59   test2,
60   bdata::make(vect_2_str(fibonacci())),
61   array_element)
62 {
63   std::cout << "test 2: \""
64     << array_element.first << "\", "
65     << array_element.second
66     << std::endl;
67   BOOST_TEST(array_element.second <= 13);
68 }
69 //]
70