• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
3 //
4 // Distributed under the Boost Software License, Version 1.0
5 // See accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt
7 //
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
10 
11 #define BOOST_TEST_MODULE TestRandomFill
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/command_queue.hpp>
16 #include <boost/compute/algorithm/count_if.hpp>
17 #include <boost/compute/algorithm/detail/random_fill.hpp>
18 #include <boost/compute/container/vector.hpp>
19 #include <boost/compute/lambda.hpp>
20 
21 #include "context_setup.hpp"
22 
23 namespace compute = boost::compute;
24 
BOOST_AUTO_TEST_CASE(random_fill_float)25 BOOST_AUTO_TEST_CASE(random_fill_float)
26 {
27     using compute::lambda::_1;
28 
29     compute::vector<float> vector(10, context);
30 
31     // fill with values between 0 and 1
32     compute::detail::random_fill(
33         vector.begin(),
34         vector.end(),
35         0.0f,
36         1.0f,
37         queue
38     );
39 
40     BOOST_CHECK_EQUAL(
41         compute::count_if(
42             vector.begin(), vector.end(), _1 < 0.0f || _1 > 1.0f, queue
43         ),
44         size_t(0)
45     );
46 
47     // fill with values between 5 and 10
48     compute::detail::random_fill(
49         vector.begin(),
50         vector.end(),
51         5.0f,
52         10.0f,
53         queue
54     );
55 
56     BOOST_CHECK_EQUAL(
57         compute::count_if(
58             vector.begin(), vector.end(), _1 < 5.0f || _1 > 10.0f, queue
59         ),
60         size_t(0)
61     );
62 
63     // fill with values between -25 and 25
64     compute::detail::random_fill(
65         vector.begin(), vector.end(), -25.0f, 25.0f, queue
66     );
67 
68     BOOST_CHECK_EQUAL(
69         compute::count_if(
70             vector.begin(), vector.end(), _1 < -25.0f || _1 > 25.0f, queue
71         ),
72         size_t(0)
73     );
74 }
75 
76 BOOST_AUTO_TEST_SUITE_END()
77