summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/compute/test/test_array.cpp
blob: 7b203f76abf4d8cb7661603565f2b06c9f8aca8c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//---------------------------------------------------------------------------//
// Copyright (c) 2013 Kyle Lutz <kyle.r.lutz@gmail.com>
//
// Distributed under the Boost Software License, Version 1.0
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
//
// See http://boostorg.github.com/compute for more information.
//---------------------------------------------------------------------------//

#define BOOST_TEST_MODULE TestArray
#include <boost/test/unit_test.hpp>

#include <boost/compute/system.hpp>
#include <boost/compute/algorithm/copy.hpp>
#include <boost/compute/container/array.hpp>
#include <boost/compute/container/vector.hpp>

#include "check_macros.hpp"
#include "context_setup.hpp"

BOOST_AUTO_TEST_CASE(concept_check)
{
    BOOST_CONCEPT_ASSERT((boost::Container<boost::compute::array<int, 3> >));
//    BOOST_CONCEPT_ASSERT((boost::SequenceConcept<boost::compute::array<int, 3> >));
    BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::iterator>));
    BOOST_CONCEPT_ASSERT((boost::RandomAccessIterator<boost::compute::array<int, 3>::const_iterator>));
}

BOOST_AUTO_TEST_CASE(size)
{
    boost::compute::array<int, 0> empty_array(context);
    BOOST_CHECK_EQUAL(empty_array.size(), size_t(0));

    boost::compute::array<int, 10> array10(context);
    BOOST_CHECK_EQUAL(array10.size(), size_t(10));
}

BOOST_AUTO_TEST_CASE(at)
{
    boost::compute::array<int, 3> array(context);
    array[0] = 3;
    array[1] = -2;
    array[2] = 5;
    BOOST_CHECK_EQUAL(array.at(0), 3);
    BOOST_CHECK_EQUAL(array.at(1), -2);
    BOOST_CHECK_EQUAL(array.at(2), 5);
    BOOST_CHECK_THROW(array.at(3), std::out_of_range);
}

BOOST_AUTO_TEST_CASE(copy_from_vector)
{
    int data[] = { 3, 6, 9, 12 };
    boost::compute::vector<int> vector(data, data + 4, queue);

    boost::compute::array<int, 4> array(context);
    boost::compute::copy(vector.begin(), vector.end(), array.begin(), queue);
    CHECK_RANGE_EQUAL(int, 4, array, (3, 6, 9, 12));
}

BOOST_AUTO_TEST_CASE(fill)
{
    boost::compute::array<int, 4> array(context);
    array.fill(0);
    CHECK_RANGE_EQUAL(int, 4, array, (0, 0, 0, 0));

    array.fill(17);
    CHECK_RANGE_EQUAL(int, 4, array, (17, 17, 17, 17));
}

BOOST_AUTO_TEST_CASE(swap)
{
    int data[] = { 1, 2, 6, 9 };
    boost::compute::array<int, 4> a(context);
    boost::compute::copy(data, data + 4, a.begin(), queue);
    CHECK_RANGE_EQUAL(int, 4, a, (1, 2, 6, 9));

    boost::compute::array<int, 4> b(context);
    b.fill(3);
    CHECK_RANGE_EQUAL(int, 4, b, (3, 3, 3, 3));

    a.swap(b);
    CHECK_RANGE_EQUAL(int, 4, a, (3, 3, 3, 3));
    CHECK_RANGE_EQUAL(int, 4, b, (1, 2, 6, 9));
}

BOOST_AUTO_TEST_SUITE_END()