7#include <gtest/gtest.h>
9#include "arccore/collections/Array.h"
10#include "arccore/collections/Array2.h"
11#include "arccore/collections/IMemoryAllocator.h"
13#include "arccore/base/FatalErrorException.h"
14#include "arccore/base/Iterator.h"
16#include "TestArrayCommon.h"
19using namespace TestArccore;
36void _dumpArray2(std::ostream& o,
const Array2<T>& a)
38 for (Int32 i = 0; i < a.dim1Size(); ++i)
39 for (Int32 j = 0; j < a.dim2Size(); ++j) {
42 o <<
"[" << i <<
"," << j <<
"]=\"" << a[i][j] <<
'"';
66 a.
resize(dim1_size, dim2_size);
67 for (Int32 i = 0; i < a.dim1Size(); ++i)
68 for (Int32 j = 0; j < a.dim2Size(); ++j) {
83 static void testMisc();
99 sh_b = _generateSharedArray2<T>(5, 3);
100 ASSERT_EQ(sh_b.dim1Size(), 5);
101 ASSERT_EQ(sh_b.dim2Size(), 3);
102 std::cout <<
"\nSH_B=";
103 _dumpArray2(std::cout, sh_b);
108 std::cout <<
"\nSH_D=";
109 _dumpArray2(std::cout, sh_d);
111 _checkSameInfoArray2(sh_b, sh_c);
112 _checkSameInfoArray2(sh_b, sh_d);
117 for (
int i = 0; i < 5; ++i) {
125 _checkSameInfoArray2(x, base_array);
126 _checkSameInfoArray2(x2, base_array);
127 _checkSameInfoArray2(x3, base_array);
128 sc1.m_test_array = x;
129 _checkSameInfoArray2(x, sc1.m_test_array);
130 sc1.m_test_array2 = x.span();
131 _checkSameInfoArray2(x, sc1.m_test_array2);
132 sc1.m_test_array3 = x.constView();
133 _checkSameInfoArray2(x, sc1.m_test_array3);
135 ASSERT_EQ(sc1.m_test_array.dim1Size(), size1);
136 ASSERT_EQ(sc1.m_test_array.dim2Size(), size2);
148 TestSharedArray2<Int32>::testMisc();
153 TestSharedArray2<IntSubClass>::testMisc();
158 TestSharedArray2<IntSubClassNoPod>::testMisc();
173 ASSERT_EQ(sh_a.dim1Size(), 3);
174 ASSERT_EQ(sh_a.dim2Size(), 2);
181 Int64 current_capacity = c.
capacity();
182 ASSERT_EQ(current_capacity, (nb * 2)) <<
"Bad capacity (test 1)";
184 ASSERT_EQ(c.
capacity(), current_capacity) <<
"Bad capacity (test 2)";
188 ASSERT_EQ(c[1][2], c(1, 2));
189#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
190 bool is_ok = c[2, 1] == c(2, 1);
197 std::cout <<
"V1=" << c.
to1DSpan() <<
"\n";
201 std::cout <<
"V2=" << c.
to1DSpan() <<
"\n";
202 ASSERT_EQ(c[0][0], 2);
203 ASSERT_EQ(c[1][0], 3);
204 ASSERT_EQ(c[0][1], 0);
205 ASSERT_EQ(c[1][1], 0);
209 ASSERT_EQ(d.dim1Size(), 4);
210 ASSERT_EQ(d.dim2Size(), 5);
214 ASSERT_EQ(d.dim1Size(), c.dim1Size());
215 ASSERT_EQ(d.dim2Size(), c.dim2Size());
218 ASSERT_EQ(e.allocator(), allocator2);
220 ASSERT_EQ(e.totalNbElement(), 42);
221 ASSERT_EQ(e.dim1Size(), 7);
222 ASSERT_EQ(e.dim2Size(), 6);
226 ASSERT_EQ(e.allocator(), d.allocator());
228 Int32 dim1_size = e.dim1Size();
229 Int32 dim2_size = e.dim2Size();
230 ASSERT_EQ(d.dim1Size(), dim1_size);
231 ASSERT_EQ(d.dim2Size(), dim2_size);
233 ASSERT_EQ(e.dim1Size(), dim1_size + 1);
234 ASSERT_EQ(e.dim2Size(), dim2_size);
235 ASSERT_EQ(e[dim1_size][0], 23);
242 _checkSameInfoArray2(g, f);
245 _checkSameInfoArray2(h, f);
248 _checkSameInfoArray2(h2, sh_a);
251 _checkSameInfoArray2(g, sh_a);
262 std::cout <<
"X1=" << c.
to1DSpan() <<
"\n";
263 ASSERT_EQ(c[0][0], 1);
264 ASSERT_EQ(c[1][0], 2);
265 ASSERT_EQ(c[0][1], 4);
266 ASSERT_EQ(c[1][1], 5);
268 std::cout <<
"X2=" << c.
to1DSpan() <<
"\n";
269 ASSERT_EQ(c[0][0], 1);
270 ASSERT_EQ(c[1][0], 2);
271 ASSERT_EQ(c[0][1], 4);
272 ASSERT_EQ(c[1][1], 5);
273 ASSERT_EQ(c[2][0], 0);
274 ASSERT_EQ(c[2][1], 0);
278 std::cout <<
"X3=" << c.
to1DSpan() <<
"\n";
279 ASSERT_EQ(c[0][0], 1);
280 ASSERT_EQ(c[1][0], 2);
281 ASSERT_EQ(c[0][1], 4);
282 ASSERT_EQ(c[1][1], 5);
283 ASSERT_EQ(c[2][0], 8);
284 ASSERT_EQ(c[2][1], 10);
285 for (
int i = 0; i < 4; ++i) {
286 ASSERT_EQ(c[i][2], 0);
287 ASSERT_EQ(c[i][3], 0);
288 ASSERT_EQ(c[i][4], 0);
290 for (
int j = 0; j < 5; ++j) {
291 ASSERT_EQ(c[3][j], 0);
292 ASSERT_EQ(c[4][j], 0);
293 ASSERT_EQ(c[5][j], 0);
#define ASSERT_TRUE(condition)
Checks that condition is true.
Class representing a classic 2D array.
void reserve(Int64 new_capacity)
Reserves memory for new_capacity elements.
Integer capacity() const
Capacity (number of allocated elements) of the array.
void resizeNoInit(Int64 new_size)
Resizes only the first dimension, leaving the second dimension unchanged.
Span< DataType > to1DSpan()
View of the array as a 1D array.
void resize(Int64 new_size)
Resizes only the first dimension, leaving the second dimension unchanged.
Integer totalNbElement() const
Total number of elements (dim1Size()*dim2Size()).
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
Interface for a memory allocator.
Memory allocator via malloc/realloc/free with listing output.
Shared 2D data vector with reference semantics.
2D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.