8#include <gtest/gtest.h>
10#include "arcane/utils/List.h"
11#include "arcane/utils/String.h"
12#include "arcane/utils/SmallArray.h"
13#include "arcane/utils/FixedArray.h"
14#include "arcane/utils/MultiArray2.h"
23TEST(Collections, Basic)
25 std::cout <<
"TEST_Collection Basic\n";
32 String str4 =
"MyStringToTest";
34 string_list.add(str1);
35 ASSERT_EQ(string_list.count(), 1);
37 string_list.add(str2);
38 ASSERT_EQ(string_list.count(), 2);
40 string_list.add(str3);
41 ASSERT_EQ(string_list.count(), 3);
45 ASSERT_EQ(string_list[0], str1);
46 ASSERT_EQ(string_list[1],
"Tata");
47 ASSERT_EQ(string_list[2], str3);
49 string_list.remove(
"Tata");
50 ASSERT_EQ(string_list.count(), 2);
51 ASSERT_EQ(string_list[0], str1);
52 ASSERT_EQ(string_list[1], str3);
55 ASSERT_EQ(string_list.count(), 0);
57 string_list.add(str4);
58 ASSERT_EQ(string_list.count(), 1);
59 string_list.add(str2);
60 ASSERT_EQ(string_list.count(), 2);
61 string_list.add(str1);
62 ASSERT_EQ(string_list.count(), 3);
73 for (Int64 i = 0, n = view.
size(); i < n; ++i)
74 ASSERT_EQ(view[i], i + 1);
79 Int64 n1 = view1.
size();
80 Int64 n2 = view2.
size();
82 for (Int64 i = 0; i < n1; ++i)
83 ASSERT_EQ(view1[i], view2[i]);
89 constexpr int N = 934;
92 ASSERT_EQ(b.guarantedAlignment({}), 0);
96 for (Int32 i = 0; i < 200; ++i)
98 ASSERT_EQ(buf1.
size(), 200);
99 _checkSmallArrayValues(buf1);
103 ASSERT_EQ(buf1.
size(), 50);
104 _checkSmallArrayValues(buf1);
106 for (Int32 i = 0; i < 200; ++i)
107 buf1.
add(50 + i + 1);
108 ASSERT_EQ(buf1.
size(), 250);
109 _checkSmallArrayValues(buf1);
111 for (
int z = 1; z < 10; ++z) {
113 for (Int32 i = 0, n = ref_buf.size(); i < n; ++i)
114 ref_buf[i] = (i + 1) * 2;
117 for (Int32 i = 0, n = ref_buf2.size(); i < n; ++i)
118 ref_buf2[i] = (i + 13) * 3;
121 _checkSmallArrayValues(buf2, ref_buf);
123 _checkSmallArrayValues(buf3, ref_buf);
125 _checkSmallArrayValues(buf4, ref_buf);
127 _checkSmallArrayValues(buf5, ref_buf);
129 _checkSmallArrayValues(buf6, ref_buf);
132 _checkSmallArrayValues(buf2, ref_buf2);
133 buf3 = ref_buf2.span();
134 _checkSmallArrayValues(buf3, ref_buf2);
135 buf4 = ref_buf2.constSpan();
136 _checkSmallArrayValues(buf4, ref_buf2);
137 buf5 = ref_buf2.view();
138 _checkSmallArrayValues(buf5, ref_buf2);
139 buf6 = ref_buf2.constView();
140 _checkSmallArrayValues(buf6, ref_buf2);
143 for (
int z = 1; z < 10; ++z) {
144 Int32 n = 5 + (z * 100);
146 ASSERT_EQ(buf3.size(), n);
147 for (Int32 i = 0; i < n; ++i)
148 buf3[i] = (i * 22) + 1;
149 for (Int32 i = 0; i < n; ++i)
150 ASSERT_EQ(buf3[i], ((i * 22) + 1));
154 std::cout <<
"Test initializer_list 1\n";
155 SmallArray<Int32, 20> buf = { 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25,
156 27, 29, 31, 33, 35, 37, 39, 41 };
158 ASSERT_EQ(buf.
size(), n);
159 for (Int32 i = 0; i < n; ++i)
160 ASSERT_EQ(buf[i], ((i * 2) + 1));
163 std::cout <<
"Test initializer_list 2\n";
166 ASSERT_EQ(buf.
size(), n);
167 for (Int32 i = 0; i < n; ++i)
168 ASSERT_EQ(buf[i], ((i * 2) + 1));
173 ASSERT_EQ(buf1.
size(), s1);
177 ASSERT_EQ(buf2.size(), s2);
186 static_assert(std::ranges::contiguous_range<FixedArray<Int32, 2>>);
190 ASSERT_EQ(empty_array.
size(), 0);
191 ASSERT_EQ(empty_array.
span().size(), 0);
195 static constexpr Int32 Size = 4;
198 ASSERT_EQ(array1.
size(), Size);
199 ASSERT_EQ(array1.
span().size(), Size);
200 ASSERT_EQ(array1.
view().size(), Size);
201 ASSERT_EQ(const_array1.span().size(), Size);
202 ASSERT_EQ(const_array1.view().size(), Size);
203 for (Int32 i = 0; i < Size; ++i) {
204 ASSERT_EQ(array1[i], 0);
205 ASSERT_EQ(array1.
span()[i], 0);
206 ASSERT_EQ(array1.
view()[i], 0);
207 ASSERT_EQ(const_array1.view()[i], 0);
214 ASSERT_EQ(array1[0], 3);
215 ASSERT_EQ(array1[1], 5);
216 ASSERT_EQ(const_array1[1], 5);
217 std::cout <<
"V[2]=" << array1[2] <<
"\n";
219 auto iter = array1.begin();
221 ASSERT_EQ(*iter, *const_array1.begin());
225 ASSERT_EQ(*iter, -1);
229 ASSERT_EQ(iter, array1.end());
230 ASSERT_EQ(iter, const_array1.end());
252 ASSERT_EQ(v[0].size(), 2);
253 ASSERT_EQ(v[0][1], 5);
254 ASSERT_EQ(v[0][1], 5);
255 ASSERT_EQ(v[1].size(), 3);
256 ASSERT_EQ(v[1][0], 27);
257 ASSERT_EQ(v[1][1], 32);
258 ASSERT_EQ(v[1][2], 21);
261 ASSERT_EQ(v2[0].size(), 3);
262 ASSERT_EQ(v2[0][0], 27);
263 ASSERT_EQ(v2[0][1], 32);
264 ASSERT_EQ(v2[0][2], 21);
265 ASSERT_EQ(v2[1].size(), 0);
#define ASSERT_FALSE(condition)
Checks that condition is false.
#define ASSERT_TRUE(condition)
Checks that condition is true.
Integer size() const
Number of elements in the vector.
void shrink()
Reallocates to free unused memory.
void resize(Int64 s)
Changes the number of elements in the array to s.
void add(ConstReferenceType val)
Adds element val to the end of the array.
base class for implementation of a typed collection.
Base class for a strongly typed collection.
constexpr __host__ __device__ ArrayView< T > view()
Modifiable view of the array.
constexpr __host__ __device__ SmallSpan< T, NbElement > span()
Modifiable view of the array.
static constexpr Int32 size()
Number of elements in the array.
Allocator with pre-allocated buffer.
Array with virtual allocator.
Implementation of a collection of elements in vector form.
Base class for multi-sized 2D arrays.
Multi-sized 2D array with reference semantics.
1D data array with pre-allocated stack buffer.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
Unicode character string.
1D data vector with value semantics (STL style).
Multi-sized 2D array with value semantics.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
List< String > StringList
Unicode string list.