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 TestArray
12 #include <boost/test/unit_test.hpp>
13
14 #include <boost/compute/system.hpp>
15 #include <boost/compute/algorithm/copy.hpp>
16 #include <boost/compute/container/array.hpp>
17 #include <boost/compute/container/vector.hpp>
18
19 #include "check_macros.hpp"
20 #include "context_setup.hpp"
21
BOOST_AUTO_TEST_CASE(concept_check)22 BOOST_AUTO_TEST_CASE(concept_check)
23 {
24 BOOST_CONCEPT_ASSERT((boost::Container<boost::compute::array<int, 3> >));
25 // BOOST_CONCEPT_ASSERT((boost::SequenceConcept<boost::compute::array<int, 3> >));
26 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::iterator>));
27 BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::const_iterator>));
28 }
29
BOOST_AUTO_TEST_CASE(size)30 BOOST_AUTO_TEST_CASE(size)
31 {
32 boost::compute::array<int, 0> empty_array(context);
33 BOOST_CHECK_EQUAL(empty_array.size(), size_t(0));
34
35 boost::compute::array<int, 10> array10(context);
36 BOOST_CHECK_EQUAL(array10.size(), size_t(10));
37 }
38
BOOST_AUTO_TEST_CASE(at)39 BOOST_AUTO_TEST_CASE(at)
40 {
41 boost::compute::array<int, 3> array(context);
42 array[0] = 3;
43 array[1] = -2;
44 array[2] = 5;
45 BOOST_CHECK_EQUAL(array.at(0), 3);
46 BOOST_CHECK_EQUAL(array.at(1), -2);
47 BOOST_CHECK_EQUAL(array.at(2), 5);
48 BOOST_CHECK_THROW(array.at(3), std::out_of_range);
49 }
50
BOOST_AUTO_TEST_CASE(copy_from_vector)51 BOOST_AUTO_TEST_CASE(copy_from_vector)
52 {
53 int data[] = { 3, 6, 9, 12 };
54 boost::compute::vector<int> vector(data, data + 4, queue);
55
56 boost::compute::array<int, 4> array(context);
57 boost::compute::copy(vector.begin(), vector.end(), array.begin(), queue);
58 CHECK_RANGE_EQUAL(int, 4, array, (3, 6, 9, 12));
59 }
60
BOOST_AUTO_TEST_CASE(fill)61 BOOST_AUTO_TEST_CASE(fill)
62 {
63 boost::compute::array<int, 4> array(context);
64 array.fill(0);
65 CHECK_RANGE_EQUAL(int, 4, array, (0, 0, 0, 0));
66
67 array.fill(17);
68 CHECK_RANGE_EQUAL(int, 4, array, (17, 17, 17, 17));
69 }
70
BOOST_AUTO_TEST_CASE(swap)71 BOOST_AUTO_TEST_CASE(swap)
72 {
73 int data[] = { 1, 2, 6, 9 };
74 boost::compute::array<int, 4> a(context);
75 boost::compute::copy(data, data + 4, a.begin(), queue);
76 CHECK_RANGE_EQUAL(int, 4, a, (1, 2, 6, 9));
77
78 boost::compute::array<int, 4> b(context);
79 b.fill(3);
80 CHECK_RANGE_EQUAL(int, 4, b, (3, 3, 3, 3));
81
82 a.swap(b);
83 CHECK_RANGE_EQUAL(int, 4, a, (3, 3, 3, 3));
84 CHECK_RANGE_EQUAL(int, 4, b, (1, 2, 6, 9));
85 }
86
87 BOOST_AUTO_TEST_SUITE_END()
88