forked from xtensor-stack/xtensor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_xstorage.cpp
76 lines (65 loc) · 2.02 KB
/
test_xstorage.cpp
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
/***************************************************************************
* Copyright (c) 2016, Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
* *
* Distributed under the terms of the BSD 3-Clause License. *
* *
* The full license is in the file LICENSE, distributed with this software. *
****************************************************************************/
#include "gtest/gtest.h"
#include "xtensor/xtensor_config.hpp"
#include "xtensor/xstorage.hpp"
#include <numeric>
namespace xt
{
using vector_type = uvector<double, XTENSOR_DEFAULT_ALLOCATOR(double)>;
TEST(uvector, constructor)
{
vector_type a;
EXPECT_EQ(size_t(0), a.size());
vector_type b(10);
EXPECT_EQ(size_t(10), b.size());
vector_type c(10, 2.5);
EXPECT_EQ(size_t(10), c.size());
EXPECT_EQ(2.5, c[2]);
std::vector<double> src(10, 1.5);
vector_type d(src.cbegin(), src.cend());
EXPECT_EQ(size_t(10), d.size());
EXPECT_EQ(1.5, d[2]);
}
TEST(uvector, resize)
{
vector_type a;
for (size_t i = 1; i < 11; ++i)
{
size_t size1 = i * 10;
a.resize(size1);
EXPECT_EQ(size1, a.size());
size_t size2 = size1 - 5;
a.resize(size2);
EXPECT_EQ(size2, a.size());
}
}
TEST(uvector, access)
{
vector_type a(10);
a[0] = 1.0;
EXPECT_EQ(1.0, a[0]);
a[3] = 3.2;
EXPECT_EQ(3.2, a[3]);
a[5] = 2.7;
EXPECT_EQ(2.7, a[5]);
a.front() = 0.0;
EXPECT_EQ(0.0, a[0]);
a.back() = 1.0;
EXPECT_EQ(1.0, a[9]);
}
TEST(uvector, iterator)
{
vector_type a(10);
std::iota(a.begin(), a.end(), 0.);
for (size_t i = 0; i < a.size(); ++i)
{
EXPECT_EQ(double(i), a[i]);
}
}
}