38 #include <pvsutil/Logger.h>
42 #include <SkelCL/Vector.h>
48 class VectorTest :
public ::testing::Test {
51 pvsutil::defaultLogger.setLoggingLevel(pvsutil::Logger::Severity::Debug);
66 TEST_F(VectorTest, CreateEmptyVector) {
69 EXPECT_TRUE(vi.
empty());
70 EXPECT_EQ(0, vi.
size());
73 TEST_F(VectorTest,
Copy) {
75 for(
unsigned i = 0; i < 5; ++i) {
79 EXPECT_FALSE(vi.
empty());
80 EXPECT_EQ(5, vi.
size());
81 for (
unsigned i = 0; i < 5; ++i) {
87 for (
unsigned i = 0; i < 5; ++i) {
91 EXPECT_FALSE(copy.empty());
92 EXPECT_EQ(vi.
size(), copy.size());
93 for (
unsigned i = 0; i < vi.
size(); ++i) {
94 EXPECT_EQ(5, copy[i]);
98 TEST_F(VectorTest, CopyWithDataOnDevice) {
100 for(
unsigned i = 0; i < 5; ++i) {
107 EXPECT_FALSE(vi.
empty());
108 EXPECT_EQ(5, vi.
size());
109 for (
unsigned i = 0; i < 5; ++i) {
117 for (
unsigned i = 0; i < 5; ++i) {
121 EXPECT_FALSE(copy.empty());
122 EXPECT_EQ(vi.
size(), copy.size());
123 for (
unsigned i = 0; i < vi.
size(); ++i) {
124 EXPECT_EQ(5, copy[i]);
128 TEST_F(VectorTest, CreateVector) {
131 EXPECT_FALSE(vi.
empty());
132 EXPECT_EQ(10, vi.
size());
133 EXPECT_EQ(0, *vi.
begin());
134 for (
int i = 0; i < 10; ++i) {
140 EXPECT_FALSE(va.empty());
141 EXPECT_EQ(5, va.size());
142 EXPECT_EQ(1, va.begin()->_a);
145 TEST_F(VectorTest, Resize) {
148 EXPECT_EQ(10, vi.
size());
151 EXPECT_EQ(11, vi.
size());
154 EXPECT_EQ(10, vi.
size());
157 EXPECT_EQ(11, vi.
size());
160 EXPECT_EQ(13, vi.
size());
162 std::vector<int> other(2);
163 vi.
insert( vi.
begin(), other.begin(), other.end() );
164 EXPECT_EQ(15, vi.
size());
167 EXPECT_EQ(14, vi.
size());
170 EXPECT_EQ(12, vi.
size());
173 EXPECT_EQ(0, vi.
size());
176 typedef struct Position {
177 Position() : _x(0), _y(0) {}
178 Position(
int x,
int y) : _x(x), _y(y) {}
183 TEST_F(VectorTest, CompleteInitialization) {
186 auto inserter = positions.begin();
187 for (
int x = 0; x < 1024; ++x)
188 for (
int y = 0; y < 768; ++y)
189 *(inserter++) = Position(x,y);
191 EXPECT_EQ(1024*768, positions.size());
193 EXPECT_EQ(23, positions[23*768+42]._x);
194 EXPECT_EQ(42, positions[23*768+42]._y);
void createDeviceBuffers() const
Create buffers on the devices involved in the current distribution.
void pop_back()
Removes the last element of the Vector.
size_type size() const
Returns the number of elements in the Vector.
void setDistribution(const detail::Distribution< Vector< U >> &distribution) const
Set a new distribution to the vector.
iterator begin()
Returns an iterator to the first element of the Vector.
SKELCL_DLL void init(detail::DeviceProperties properties=allDevices())
Initializes the SkelCL library. This function (or another init function) has to be called prior to ev...
void clear()
Removes all elements from the Vector.
void resize(size_type count, T value=T())
Resizes the container to contain count elements.
void dataOnDeviceModified() const
Marks the data on the device as been modified.
SKELCL_DLL detail::DeviceProperties nDevices(size_t n)
Creates a detail::DeviceProperties object representing n devices. This object should be used as param...
The Vector class is a one dimensional container which makes its data accessible on the host as well a...
std::unique_ptr< skelcl::detail::Distribution< C< T > > > Copy(const C< T > &c, typename identity< std::function< T(const T &, const T &)>>::type combineFunc=nullptr)
Factory function to create a CopyDistribution with the types of the given container.
iterator insert(iterator pos, const T &value)
Inserts copy of value at the specified location in the Vector.
iterator erase(iterator pos)
Remove the specified element from the Vector.
void push_back(const T &value)
Appends a copy of the given element value to the end of the Vector.
SKELCL_DLL void terminate()
Frees all resources allocated internally by SkelCL.
void copyDataToDevices() const
Copies data from the host to the devices involved in the current distribution.
bool empty() const
Checks if the Vector has no elements, i.e. whether begin() == end()