10000 Adding tests · xtensor-stack/xtensor-python@f7c696e · GitHub
[go: up one dir, main page]

Skip to content

Commit f7c696e

Browse files
committed
Adding tests
1 parent a26ca70 commit f7c696e

File tree

1 file changed

+44
-21
lines changed

1 file changed

+44
-21
lines changed

test/test_pyarray.cpp

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,68 @@ namespace xt
3838
TEST(pyarray, initializer_constructor)
3939
{
4040
pyarray<int> r
41-
{{{ 0, 1, 2},
42-
{ 3, 4, 5},
43-
{ 6, 7, 8}},
44-
{{ 9, 10, 11},
45-
{12, 13, 14},
46-
{15, 16, 17}}};
41+
{{{ 0, 1, 2},
42+
{ 3, 4, 5},
43+
{ 6, 7, 8}},
44+
{{ 9, 10, 11},
45+
{12, 13, 14},
46+
{15, 16, 17}}};
4747

4848
EXPECT_EQ(r.layout(), xt::layout_type::row_major);
4949
EXPECT_EQ(r.dimension(), 3);
5050
EXPECT_EQ(r(0, 0, 1), 1);
5151
EXPECT_EQ(r.shape()[0], 2);
5252

5353
pyarray<int, xt::layout_type::column_major> c
54-
{{{ 0, 1, 2},
55-
{ 3, 4, 5},
56-
{ 6, 7, 8}},
57-
{{ 9, 10, 11},
58-
{12, 13, 14},
59-
{15, 16, 17}}};
54+
{{{ 0, 1, 2},
55+
{ 3, 4, 5},
56+
{ 6, 7, 8}},
57+
{{ 9, 10, 11},
58+
{12, 13, 14},
59+
{15, 16, 17}}};
6060

6161
EXPECT_EQ(c.layout(), xt::layout_type::column_major);
6262
EXPECT_EQ(c.dimension(), 3);
6363
EXPECT_EQ(c(0, 0, 1), 1);
6464
EXPECT_EQ(c.shape()[0], 2);
6565

6666
pyarray<int, xt::layout_type::dynamic> d
67-
{{{ 0, 1, 2},
68-
{ 3, 4, 5},
69-
{ 6, 7, 8}},
70-
{{ 9, 10, 11},
71-
{12, 13, 14},
72-
{15, 16, 17}}};
67+
{{{ 0, 1, 2},
68+
{ 3, 4, 5},
69+
{ 6, 7, 8}},
70+
{{ 9, 10, 11},
71+
{12, 13, 14},
72+
{15, 16, 17}}};
7373

7474
EXPECT_EQ(d.layout(), xt::layout_type::row_major);
7575
EXPECT_EQ(d.dimension(), 3);
7676
EXPECT_EQ(d(0, 0, 1), 1);
7777
EXPECT_EQ(d.shape()[0], 2);
7878
}
7979

80+
TEST(pyarray, expression)
81+
{
82+
pyarray<int> a = xt::empty<int>({});
83+
84+
EXPECT_EQ(a.layout(), xt::layout_type::row_major);
85+
EXPECT_EQ(a.dimension(), 0);
86+
EXPECT_EQ(a.size(), 1);
87+
88+
pyarray<int> b = xt::empty<int>({5});
89+
90+
EXPECT_EQ(b.layout(), xt::layout_type::row_major);
91+
EXPECT_EQ(b.dimension(), 1);
92+
EXPECT_EQ(b.size(), 5);
93+
94+
pyarray<int> c = xt::empty<int>({5, 3});
95+
96+
EXPECT_EQ(c.layout(), xt::layout_type::row_major);
97+
EXPECT_EQ(c.dimension(), 2);
98+
EXPECT_EQ(c.size(), 15);
99+
EXPECT_EQ(c.shape(0), 5);
100+
EXPECT_EQ(c.shape(1), 3);
101+
}
102+
80103
TEST(pyarray, shaped_constructor)
81104
{
82105
{
@@ -86,7 +109,7 @@ namespace xt
86109
compare_shape(ra, rm);
87110
EXPECT_EQ(layout_type::row_major, ra.layout());
88111
}
89-
112+
90113
{
91114
SCOPED_TRACE("column_major constructor");
92115
column_major_result<> cm;
@@ -150,7 +173,7 @@ namespace xt
150173
central_major_result<> res;
151174
int value = 2;
152175
pyarray<int> a(res.m_shape, res.m_strides, value);
153-
176+
154177
{
155178
SCOPED_TRACE("copy constructor");
156179
pyarray<int> b(a);
@@ -277,7 +300,7 @@ namespace xt
277300
EXPECT_EQ(2, a1(1));
278301
EXPECT_EQ(4, a2(1, 1));
279302
}
280-
303+
281304
TEST(pyarray, zerod)
282305
{
283306
pyarray<int> a;

0 commit comments

Comments
 (0)
0