summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/compute/test/test_extents.cpp
blob: 38ab092fe69f1c53bfb9f51bf9d9538ae647ef34 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
//---------------------------------------------------------------------------//
// Copyright (c) 2013-2014 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 TestExtents
#include <boost/test/unit_test.hpp>

#include <algorithm>
#include <vector>

#include <boost/compute/utility/dim.hpp>
#include <boost/compute/utility/extents.hpp>

#include "context_setup.hpp"

namespace compute = boost::compute;

#ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
BOOST_AUTO_TEST_CASE(initialize)
{
    compute::extents<1> one(1);
    BOOST_CHECK_EQUAL(one[0], size_t(1));

    compute::extents<3> xyz = compute::dim(1, 2, 3);
    BOOST_CHECK_EQUAL(xyz[0], size_t(1));
    BOOST_CHECK_EQUAL(xyz[1], size_t(2));
    BOOST_CHECK_EQUAL(xyz[2], size_t(3));
}
#endif

BOOST_AUTO_TEST_CASE(size)
{
    BOOST_CHECK_EQUAL(compute::extents<1>().size(), size_t(1));
    BOOST_CHECK_EQUAL(compute::extents<2>().size(), size_t(2));
    BOOST_CHECK_EQUAL(compute::extents<3>().size(), size_t(3));
}

BOOST_AUTO_TEST_CASE(subscript_operator)
{
    compute::extents<3> xyz;
    BOOST_CHECK_EQUAL(xyz[0], size_t(0));
    BOOST_CHECK_EQUAL(xyz[1], size_t(0));
    BOOST_CHECK_EQUAL(xyz[2], size_t(0));

    xyz[0] = size_t(10);
    xyz[1] = size_t(20);
    xyz[2] = size_t(30);
    BOOST_CHECK_EQUAL(xyz[0], size_t(10));
    BOOST_CHECK_EQUAL(xyz[1], size_t(20));
    BOOST_CHECK_EQUAL(xyz[2], size_t(30));
}

#ifndef BOOST_COMPUTE_NO_HDR_INITIALIZER_LIST
BOOST_AUTO_TEST_CASE(data)
{
    compute::extents<3> xyz = compute::dim(5, 6, 7);
    BOOST_CHECK_EQUAL(xyz.data()[0], size_t(5));
    BOOST_CHECK_EQUAL(xyz.data()[1], size_t(6));
    BOOST_CHECK_EQUAL(xyz.data()[2], size_t(7));
}

BOOST_AUTO_TEST_CASE(linear)
{
    compute::extents<2> uv = compute::dim(16, 16);
    BOOST_CHECK_EQUAL(uv.linear(), size_t(256));
}

BOOST_AUTO_TEST_CASE(equality_operator)
{
    BOOST_CHECK(compute::dim(10, 20) == compute::dim(10, 20));
    BOOST_CHECK(compute::dim(20, 10) != compute::dim(10, 20));
}

BOOST_AUTO_TEST_CASE(empty_dim)
{
    BOOST_CHECK(compute::dim<0>() == compute::dim());
    BOOST_CHECK(compute::dim<1>() == compute::dim(0));
    BOOST_CHECK(compute::dim<2>() == compute::dim(0, 0));
    BOOST_CHECK(compute::dim<3>() == compute::dim(0, 0, 0));
}

BOOST_AUTO_TEST_CASE(copy_to_vector)
{
    compute::extents<3> exts = compute::dim(4, 5, 6);

    std::vector<size_t> vec(3);
    std::copy(exts.begin(), exts.end(), vec.begin());
    BOOST_CHECK_EQUAL(vec[0], size_t(4));
    BOOST_CHECK_EQUAL(vec[1], size_t(5));
    BOOST_CHECK_EQUAL(vec[2], size_t(6));
}
#endif

BOOST_AUTO_TEST_SUITE_END()