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;
37void _dumpArray2(std::ostream& o,
const Array2<T>& a)
39 for (Int32 i = 0; i < a.dim1Size(); ++i)
40 for (Int32 j = 0; j < a.dim2Size(); ++j) {
43 o <<
"[" << i <<
"," << j <<
"]=\"" << a[i][j] <<
'"';
67 a.
resize(dim1_size, dim2_size);
68 for (Int32 i = 0; i < a.dim1Size(); ++i)
69 for (Int32 j = 0; j < a.dim2Size(); ++j) {
84 static void testMisc();
100 sh_b = _generateSharedArray2<T>(5, 3);
101 ASSERT_EQ(sh_b.dim1Size(), 5);
102 ASSERT_EQ(sh_b.dim2Size(), 3);
103 std::cout <<
"\nSH_B=";
104 _dumpArray2(std::cout, sh_b);
109 std::cout <<
"\nSH_D=";
110 _dumpArray2(std::cout, sh_d);
112 _checkSameInfoArray2(sh_b, sh_c);
113 _checkSameInfoArray2(sh_b, sh_d);
118 for (
int i = 0; i < 5; ++i) {
126 _checkSameInfoArray2(x, base_array);
127 _checkSameInfoArray2(x2, base_array);
128 _checkSameInfoArray2(x3, base_array);
129 sc1.m_test_array = x;
130 _checkSameInfoArray2(x, sc1.m_test_array);
131 sc1.m_test_array2 = x.span();
132 _checkSameInfoArray2(x, sc1.m_test_array2);
133 sc1.m_test_array3 = x.constView();
134 _checkSameInfoArray2(x, sc1.m_test_array3);
136 ASSERT_EQ(sc1.m_test_array.dim1Size(), size1);
137 ASSERT_EQ(sc1.m_test_array.dim2Size(), size2);
149 TestSharedArray2<Int32>::testMisc();
154 TestSharedArray2<IntSubClass>::testMisc();
159 TestSharedArray2<IntSubClassNoPod>::testMisc();
174 ASSERT_EQ(sh_a.dim1Size(), 3);
175 ASSERT_EQ(sh_a.dim2Size(), 2);
182 Int64 current_capacity = c.
capacity();
183 ASSERT_EQ(current_capacity, (nb * 2)) <<
"Bad capacity (test 1)";
185 ASSERT_EQ(c.
capacity(), current_capacity) <<
"Bad capacity (test 2)";
189 ASSERT_EQ(c[1][2], c(1, 2));
190#ifdef ARCCORE_HAS_MULTI_SUBSCRIPT
191 bool is_ok = c[2, 1] == c(2, 1);
198 std::cout <<
"V1=" << c.
to1DSpan() <<
"\n";
202 std::cout <<
"V2=" << c.
to1DSpan() <<
"\n";
203 ASSERT_EQ(c[0][0], 2);
204 ASSERT_EQ(c[1][0], 3);
205 ASSERT_EQ(c[0][1], 0);
206 ASSERT_EQ(c[1][1], 0);
210 ASSERT_EQ(d.dim1Size(), 4);
211 ASSERT_EQ(d.dim2Size(), 5);
215 ASSERT_EQ(d.dim1Size(), c.dim1Size());
216 ASSERT_EQ(d.dim2Size(), c.dim2Size());
219 ASSERT_EQ(e.allocator(), allocator2);
221 ASSERT_EQ(e.totalNbElement(), 42);
222 ASSERT_EQ(e.dim1Size(), 7);
223 ASSERT_EQ(e.dim2Size(), 6);
227 ASSERT_EQ(e.allocator(), d.allocator());
229 Int32 dim1_size = e.dim1Size();
230 Int32 dim2_size = e.dim2Size();
231 ASSERT_EQ(d.dim1Size(), dim1_size);
232 ASSERT_EQ(d.dim2Size(), dim2_size);
234 ASSERT_EQ(e.dim1Size(), dim1_size + 1);
235 ASSERT_EQ(e.dim2Size(), dim2_size);
236 ASSERT_EQ(e[dim1_size][0], 23);
243 _checkSameInfoArray2(g, f);
246 _checkSameInfoArray2(h, f);
249 _checkSameInfoArray2(h2, sh_a);
252 _checkSameInfoArray2(g, sh_a);
263 std::cout <<
"X1=" << c.
to1DSpan() <<
"\n";
264 ASSERT_EQ(c[0][0], 1);
265 ASSERT_EQ(c[1][0], 2);
266 ASSERT_EQ(c[0][1], 4);
267 ASSERT_EQ(c[1][1], 5);
269 std::cout <<
"X2=" << c.
to1DSpan() <<
"\n";
270 ASSERT_EQ(c[0][0], 1);
271 ASSERT_EQ(c[1][0], 2);
272 ASSERT_EQ(c[0][1], 4);
273 ASSERT_EQ(c[1][1], 5);
274 ASSERT_EQ(c[2][0], 0);
275 ASSERT_EQ(c[2][1], 0);
279 std::cout <<
"X3=" << c.
to1DSpan() <<
"\n";
280 ASSERT_EQ(c[0][0], 1);
281 ASSERT_EQ(c[1][0], 2);
282 ASSERT_EQ(c[0][1], 4);
283 ASSERT_EQ(c[1][1], 5);
284 ASSERT_EQ(c[2][0], 8);
285 ASSERT_EQ(c[2][1], 10);
286 for (
int i = 0; i < 4; ++i) {
287 ASSERT_EQ(c[i][2], 0);
288 ASSERT_EQ(c[i][3], 0);
289 ASSERT_EQ(c[i][4], 0);
291 for (
int j = 0; j < 5; ++j) {
292 ASSERT_EQ(c[3][j], 0);
293 ASSERT_EQ(c[4][j], 0);
294 ASSERT_EQ(c[5][j], 0);
#define ASSERT_TRUE(condition)
Vérifie que condition est vrai.
Tableau 2D d'items de types quelconques.
void reserve(Int64 new_capacity)
Réserve de la mémoire pour new_capacity éléments.
Integer capacity() const
Capacité (nombre d'éléments alloués) du tableau.
void resizeNoInit(Int64 new_size)
Redimensionne uniquement la première dimension en laissant la deuxième à l'identique.
Span< DataType > to1DSpan()
Vue du tableau sous forme de tableau 1D.
Integer totalNbElement() const
Nombre total d'éléments (dim1Size()*dim2Size())
void resize(Integer size)
Redimensionnement de la deuxième dimension du tableau.
Tableau d'items de types quelconques.
void resize(Int64 s)
Change le nombre d'éléments du tableau à s.
Interface d'un allocateur pour la mémoire.
Allocateur mémoire via malloc/realloc/free avec impression listing.
Vecteur de données 2D partagées avec sémantique par référence.
Vecteur de données 2D avec sémantique par valeur (style STL).
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.
Espace de nom de Arccore.