Nektar++
testNekSharedArray.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: testNekSharedArray.cpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Test code for Nektar::shared_array
32//
33///////////////////////////////////////////////////////////////////////////////
34
38#include <UnitTests/util.h>
39
42
43#include <boost/test/test_tools.hpp>
44#include <boost/test/unit_test.hpp>
45#include <iostream>
46
48{
49
51{
52public:
54 {
55 a[0] = 0.0;
56 a[1] = 1.0;
57 a[2] = 2.0;
58 a[3] = 3.0;
59 a[4] = 4.0;
60 }
61
62 // out should refer to the same array as a, so any
63 // changes in out should be reflected in a.
65 {
66 out = a;
67 }
68
69 // Does nothing - the assignment goes into a temporary and is
70 // immediately lost.
72 {
73 out = a;
74 }
75
76 // The following should not compile because the assignment it going into a
77 // C++ const variable.
78 // void getNonConstByConstReference(const Array<OneD,
79 // NekDouble>& out)
80 // {
81 // out = a;
82 // }
83 //
84 // void getNonConstByConstValue(const Array<OneD, NekDouble>
85 // out)
86 // {
87 // out = a;
88 // }
89
90 // out should refer to the same array as a, so any
91 // changes in out should be reflected in a.
93 {
94 out = a;
95 }
96
97 // Does nothing - the assignment goes into a temporary and is
98 // immediately lost.
100 {
101 out = a;
102 }
103
106};
107
108BOOST_AUTO_TEST_CASE(TestParameterPopulation)
109{
111
112 Array<OneD, NekDouble> zero(5, 0.0);
113 Array<OneD, NekDouble> temp(zero);
114 Array<OneD, const NekDouble> const_zero(5, 0.0);
115 Array<OneD, const NekDouble> const_temp(const_zero);
116
117 obj.getNonConstByReference(temp);
118 BOOST_CHECK(temp == obj.a);
119
120 temp = zero;
121 obj.getNonConstByValue(temp);
122 BOOST_CHECK(temp == zero);
123 BOOST_CHECK(temp != obj.a);
124
125 // should not compile.
126 // obj.getNonConstByReference(const_temp);
127 // obj.getNonConstByValue(const_temp);
128
129 // Now the ConstArray versions.
130 obj.getConstByReference(const_temp);
131 BOOST_CHECK(const_temp == obj.a);
132 BOOST_CHECK(const_temp != const_zero);
133 const_temp = const_zero;
134 BOOST_CHECK(const_temp == const_zero);
135
136 obj.getConstByValue(const_temp);
137 BOOST_CHECK(const_temp == const_zero);
138 BOOST_CHECK(const_temp != obj.a);
139}
140
141BOOST_AUTO_TEST_CASE(TestEmptyConstructor)
142{
143 {
147 CountedObject<double>::Check(0, 0, 0, 0, 0, 0);
148
149 BOOST_CHECK(a.begin() == a.end());
150 BOOST_CHECK(b.begin() == b.end());
151
152 BOOST_CHECK_EQUAL(a.size(), 0);
153 BOOST_CHECK_EQUAL(b.size(), 0);
154
155 BOOST_CHECK_EQUAL(a.num_dimensions(), 1);
156 BOOST_CHECK_EQUAL(b.num_dimensions(), 1);
157 }
158 CountedObject<double>::Check(0, 0, 0, 0, 0, 0);
159
160 {
164 CountedObject<double>::Check(0, 0, 0, 0, 0, 0);
165
166 BOOST_CHECK(a.begin() == a.end());
167 BOOST_CHECK(b.begin() == b.end());
168
169 BOOST_CHECK_EQUAL(a.size(), 0);
170 BOOST_CHECK_EQUAL(b.size(), 0);
171
172 BOOST_CHECK_EQUAL(a.num_dimensions(), 2);
173 BOOST_CHECK_EQUAL(b.num_dimensions(), 2);
174 }
175 CountedObject<double>::Check(0, 0, 0, 0, 0, 0);
176}
177
178BOOST_AUTO_TEST_CASE(TestUninitializedConstructor)
179{
180 {
182
185 CountedObject<double>::Check(15, 0, 0, 0, 0, 0);
186
187 BOOST_CHECK(a.begin() != a.end());
188 BOOST_CHECK(b.begin() != b.end());
189
190 BOOST_CHECK_EQUAL(a.size(), 5);
191 BOOST_CHECK_EQUAL(b.size(), 10);
192
193 BOOST_CHECK_EQUAL(a.num_dimensions(), 1);
194 BOOST_CHECK_EQUAL(b.num_dimensions(), 1);
195 }
196 CountedObject<double>::Check(15, 0, 15, 0, 0, 0);
197
198 {
200
203 CountedObject<double>::Check(150, 0, 0, 0, 0, 0);
204
205 BOOST_CHECK(a.begin() != a.end());
206 BOOST_CHECK(b.begin() != b.end());
207
208 BOOST_CHECK_EQUAL(a.size(), 50);
209 BOOST_CHECK_EQUAL(b.size(), 100);
210
211 BOOST_CHECK_EQUAL(a.shape()[0], 5);
212 BOOST_CHECK_EQUAL(a.shape()[1], 10);
213 BOOST_CHECK_EQUAL(b.shape()[0], 10);
214 BOOST_CHECK_EQUAL(b.shape()[1], 10);
215
216 BOOST_CHECK_EQUAL(a.num_dimensions(), 2);
217 BOOST_CHECK_EQUAL(b.num_dimensions(), 2);
218 }
219 CountedObject<double>::Check(150, 0, 150, 0, 0, 0);
220}
221
222BOOST_AUTO_TEST_CASE(TestSingleValueInitialization)
223{
224 {
225 CountedObject<double> initValue(98);
227
229 Array<OneD, CountedObject<double>> b(10, initValue);
230 CountedObject<double>::Check(0, 0, 0, 15, 0, 0);
231
232 BOOST_CHECK(a.begin() != a.end());
233 BOOST_CHECK(b.begin() != b.end());
234
235 BOOST_CHECK_EQUAL(a.size(), 5);
236 BOOST_CHECK_EQUAL(b.size(), 10);
237
238 BOOST_CHECK_EQUAL(a.num_dimensions(), 1);
239 BOOST_CHECK_EQUAL(b.num_dimensions(), 1);
240
241 for (Array<OneD, const CountedObject<double>>::const_iterator iter =
242 a.begin();
243 iter != a.end(); ++iter)
244 {
245 BOOST_CHECK(*iter == initValue);
246 }
247
248 for (Array<OneD, CountedObject<double>>::iterator iter = b.begin();
249 iter != b.end(); ++iter)
250 {
251 BOOST_CHECK(*iter == initValue);
252 }
253 }
254 CountedObject<double>::Check(0, 0, 16, 15, 0, 0);
255
256 {
257 CountedObject<double> initValue(98);
259
260 Array<TwoD, const CountedObject<double>> a(5, 10, initValue);
261 Array<TwoD, CountedObject<double>> b(10, 10, initValue);
262 CountedObject<double>::Check(0, 0, 0, 150, 0, 0);
263
264 BOOST_CHECK(a.begin() != a.end());
265 BOOST_CHECK(b.begin() != b.end());
266
267 BOOST_CHECK_EQUAL(a.size(), 50);
268 BOOST_CHECK_EQUAL(b.size(), 100);
269
270 BOOST_CHECK_EQUAL(a.shape()[0], 5);
271 BOOST_CHECK_EQUAL(a.shape()[1], 10);
272 BOOST_CHECK_EQUAL(b.shape()[0], 10);
273 BOOST_CHECK_EQUAL(b.shape()[1], 10);
274
275 BOOST_CHECK_EQUAL(a.num_dimensions(), 2);
276 BOOST_CHECK_EQUAL(b.num_dimensions(), 2);
277
278 using size_type = Array<TwoD, double>::size_type;
279 for (size_type i = 0; i < a.shape()[0]; ++i)
280 {
281 for (size_type j = 0; j < a.shape()[1]; ++j)
282 {
283 BOOST_CHECK(a[i][j] == initValue);
284 }
285 }
286
287 for (size_type i = 0; i < b.shape()[0]; ++i)
288 {
289 for (size_type j = 0; j < b.shape()[1]; ++j)
290 {
291 BOOST_CHECK(b[i][j] == initValue);
292 }
293 }
294 }
295 CountedObject<double>::Check(0, 0, 151, 150, 0, 0);
296}
297
298BOOST_AUTO_TEST_CASE(TestPopulationFromCArray)
299{
300 {
301 CountedObject<double> a_array[] = {
304 CountedObject<double> b_array[] = {
309
312 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
313
314 BOOST_CHECK(a.begin() != a.end());
315 BOOST_CHECK(b.begin() != b.end());
316
317 BOOST_CHECK_EQUAL(a.size(), 4);
318 BOOST_CHECK_EQUAL(b.size(), 5);
319
320 BOOST_CHECK_EQUAL(a.num_dimensions(), 1);
321 BOOST_CHECK_EQUAL(b.num_dimensions(), 1);
322
323 using size_type = Array<OneD, double>::size_type;
324 for (size_type i = 0; i < a.size(); ++i)
325 {
326 BOOST_CHECK(a[i] == a_array[i]);
327 }
328
329 for (size_type i = 0; i < b.size(); ++i)
330 {
331 BOOST_CHECK(b[i] == b_array[i]);
332 }
333 }
334 CountedObject<double>::Check(0, 0, 18, 9, 0, 0);
335
336 {
337 double a_array[] = {1.0, 2.0, 3.0, 4.0};
338 double b_array[] = {5.0, 6.0, 7.0, 8.0, 9.0};
339 Array<OneD, double> a(4, a_array);
340 Array<OneD, double> b(5, b_array);
341
342 BOOST_CHECK(a.size() == 4);
343 BOOST_CHECK(b.size() == 5);
344
345 using size_type = Array<OneD, double>::size_type;
346 for (size_type i = 0; i < a.size(); ++i)
347 {
348 BOOST_CHECK(a[i] == a_array[i]);
349 }
350
351 for (size_type i = 0; i < b.size(); ++i)
352 {
353 BOOST_CHECK(b[i] == b_array[i]);
354 }
355 }
356}
357
358BOOST_AUTO_TEST_CASE(TestCopyConstruction)
359{
360 {
361 CountedObject<double> a_array[] = {
364 CountedObject<double> b_array[] = {
369
372 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
373
374 {
378
379 BOOST_CHECK_EQUAL(c.size(), a.size());
380 BOOST_CHECK_EQUAL(e.size(), a.size());
381 BOOST_CHECK_EQUAL(d.size(), b.size());
382 BOOST_CHECK(c.data() == a.data());
383 BOOST_CHECK(e.data() == a.data());
384 BOOST_CHECK(d.data() == b.data());
385
386 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
387 }
388 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
389 }
390 CountedObject<double>::Check(0, 0, 18, 9, 0, 0);
391
392 {
393 // Test offset copy constructor.
394 CountedObject<double> a_array[] = {
397 CountedObject<double> b_array[] = {
404 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
405
409
410 BOOST_CHECK_EQUAL(a_off[0].value, a[1].value);
411 BOOST_CHECK_EQUAL(a_off[1].value, a[2].value);
412 BOOST_CHECK_EQUAL(a_off[2].value, a[3].value);
413 BOOST_CHECK_EQUAL(a_off.size(), 3);
414
415 BOOST_CHECK_EQUAL(b_off[0].value, b[2].value);
416 BOOST_CHECK_EQUAL(b_off[1].value, b[3].value);
417 BOOST_CHECK_EQUAL(b_off[2].value, b[4].value);
418 BOOST_CHECK_EQUAL(b_off.size(), 3);
419
420 BOOST_CHECK_EQUAL(bb_off[0].value, b[2].value);
421 BOOST_CHECK_EQUAL(bb_off[1].value, b[3].value);
422 BOOST_CHECK_EQUAL(bb_off[2].value, b[4].value);
423 BOOST_CHECK_EQUAL(bb_off.size(), 3);
424 }
425}
426
427BOOST_AUTO_TEST_CASE(Test1DAssignmentOperator)
428{
429 {
430 // 1D
431 CountedObject<double> a_array[] = {
434 CountedObject<double> b_array[] = {
441 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
442
443 {
447 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
448
449 BOOST_CHECK_EQUAL(lhs_a.size(), 0);
450 BOOST_CHECK_EQUAL(lhs_b1.size(), 0);
451 BOOST_CHECK_EQUAL(lhs_b2.size(), 0);
452
453 {
454 lhs_a = a;
455 lhs_b1 = b;
456 lhs_b2 = b;
457 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
458
459 BOOST_CHECK_EQUAL(lhs_a.size(), a.size());
460 BOOST_CHECK_EQUAL(lhs_b1.size(), b.size());
461 BOOST_CHECK_EQUAL(lhs_b2.size(), b.size());
462 BOOST_CHECK_EQUAL(lhs_a.data(), a.data());
463 BOOST_CHECK_EQUAL(lhs_b1.data(), b.data());
464 BOOST_CHECK_EQUAL(lhs_b2.data(), b.data());
465
466 using size_type = Array<OneD, double>::size_type;
467 for (size_type i = 0; i < a.size(); ++i)
468 {
469 BOOST_CHECK(lhs_a[i] == a[i]);
470 }
471
472 for (size_type i = 0; i < b.size(); ++i)
473 {
474 BOOST_CHECK(lhs_b1[i] == b[i]);
475 BOOST_CHECK(lhs_b2[i] == b[i]);
476 }
477 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
478 }
479 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
480 }
481 CountedObject<double>::Check(0, 0, 0, 9, 0, 0);
482 }
483}
484
485BOOST_AUTO_TEST_CASE(Test2DAssignmentOperator)
486{
487 {
488 // 2D
489 CountedObject<double> initValue(98);
491
492 Array<TwoD, const CountedObject<double>> a(5, 10, initValue);
493 Array<TwoD, CountedObject<double>> b(10, 10, initValue);
494 CountedObject<double>::Check(0, 0, 0, 150, 0, 0);
495
496 BOOST_CHECK(a.begin() != a.end());
497 BOOST_CHECK(b.begin() != b.end());
498
499 BOOST_CHECK_EQUAL(a.size(), 50);
500 BOOST_CHECK_EQUAL(b.size(), 100);
501 BOOST_CHECK_EQUAL(a.shape()[0], 5);
502 BOOST_CHECK_EQUAL(a.shape()[1], 10);
503 BOOST_CHECK_EQUAL(b.shape()[0], 10);
504 BOOST_CHECK_EQUAL(b.shape()[1], 10);
505
506 BOOST_CHECK_EQUAL(a.num_dimensions(), 2);
507 BOOST_CHECK_EQUAL(b.num_dimensions(), 2);
508
509 {
513
514 BOOST_CHECK_EQUAL(lhs_a.size(), 0);
515 BOOST_CHECK_EQUAL(lhs_b1.size(), 0);
516 BOOST_CHECK_EQUAL(lhs_b2.size(), 0);
517
518 lhs_a = a;
519 lhs_b1 = b;
520 lhs_b2 = b;
521 CountedObject<double>::Check(0, 0, 0, 150, 0, 0);
522
523 BOOST_CHECK_EQUAL(lhs_a.size(), a.size());
524 BOOST_CHECK_EQUAL(lhs_b1.size(), b.size());
525 BOOST_CHECK_EQUAL(lhs_b2.size(), b.size());
526 BOOST_CHECK_EQUAL(lhs_a.shape()[0], a.shape()[0]);
527 BOOST_CHECK_EQUAL(lhs_a.shape()[1], a.shape()[1]);
528
529 BOOST_CHECK_EQUAL(lhs_b1.shape()[0], b.shape()[0]);
530 BOOST_CHECK_EQUAL(lhs_b1.shape()[1], b.shape()[1]);
531
532 BOOST_CHECK_EQUAL(lhs_b2.shape()[0], b.shape()[0]);
533 BOOST_CHECK_EQUAL(lhs_b2.shape()[1], b.shape()[1]);
534
535 using size_type = Array<TwoD, double>::size_type;
536 for (size_type i = 0; i < a.shape()[0]; ++i)
537 {
538 for (size_type j = 0; j < a.shape()[1]; ++j)
539 {
540 BOOST_CHECK(a[i][j] == initValue);
541 BOOST_CHECK(lhs_a[i][j] == a[i][j]);
542 }
543 }
544
545 for (size_type i = 0; i < b.shape()[0]; ++i)
546 {
547 for (size_type j = 0; j < b.shape()[1]; ++j)
548 {
549 BOOST_CHECK(b[i][j] == initValue);
550 BOOST_CHECK(lhs_b1[i][j] == b[i][j]);
551 BOOST_CHECK(lhs_b2[i][j] == b[i][j]);
552 }
553 }
554 }
555 CountedObject<double>::Check(0, 0, 0, 150, 0, 0);
556 }
557
558 CountedObject<double>::Check(0, 0, 151, 150, 0, 0);
559}
560
561BOOST_AUTO_TEST_CASE(TestOffsetAssignmentOperator)
562{
563 double a[] = {1.0, 2.0, 3.0, 4.0, 5.0};
564 double b[] = {10.0, 20.0, 30.0, 40.0};
565
566 Array<OneD, NekDouble> rhs_a(5, a);
568
569 Array<OneD, NekDouble> offset_a = rhs_a + 2;
570 ;
571 Array<OneD, const NekDouble> offset_b = rhs_a + 2;
572
575
576 lhs_a = offset_a;
577 lhs_b = offset_b;
578
579 BOOST_CHECK_EQUAL(lhs_a.size(), offset_a.size());
580 BOOST_CHECK_EQUAL(lhs_b.size(), offset_b.size());
581
582 using size_type = Array<TwoD, double>::size_type;
583 for (size_type i = 0; i < lhs_a.size(); ++i)
584 {
585 BOOST_CHECK(lhs_a[i] == offset_a[i]);
586 }
587
588 for (size_type i = 0; i < lhs_b.size(); ++i)
589 {
590 BOOST_CHECK(lhs_b[i] == offset_b[i]);
591 }
592}
593
594BOOST_AUTO_TEST_CASE(Test1DAccessOperator)
595{
597 // Normal access.
598 double a[] = {1.0, 2.0, 3.0, 4.0, 5.0};
599 double b[] = {10.0, 20.0, 30.0, 40.0};
600
601 Array<OneD, NekDouble> rhs_a(5, a);
603
604 BOOST_CHECK_EQUAL(rhs_a[0], 1.0);
605 BOOST_CHECK_EQUAL(rhs_a[1], 2.0);
606 BOOST_CHECK_EQUAL(rhs_a[2], 3.0);
607 BOOST_CHECK_EQUAL(rhs_a[3], 4.0);
608 BOOST_CHECK_EQUAL(rhs_a[4], 5.0);
609
610 BOOST_CHECK_EQUAL(rhs_b[0], 10.0);
611 BOOST_CHECK_EQUAL(rhs_b[1], 20.0);
612 BOOST_CHECK_EQUAL(rhs_b[2], 30.0);
613 BOOST_CHECK_EQUAL(rhs_b[3], 40.0);
614#if defined(NEKTAR_DEBUG) || defined(NEKTAR_FULL_DEBUG)
615 BOOST_CHECK_NO_THROW(rhs_a[4]);
616 BOOST_CHECK_THROW(rhs_a[5], ErrorUtil::NekError);
617 BOOST_CHECK_NO_THROW(rhs_b[3]);
618 BOOST_CHECK_THROW(rhs_b[4], ErrorUtil::NekError);
619#endif
620}
621
622BOOST_AUTO_TEST_CASE(Test2DAccessOperator)
623{
624 {
625 NekDouble a_vals[] = {1.0, 2.0, 3.0, 4.0, 5.0,
626 6.0, 7.0, 8.0, 9.0, 10.0};
627 Array<TwoD, NekDouble> a(5, 2, a_vals);
628
629 BOOST_CHECK_EQUAL(a.GetRows(), 5);
630 BOOST_CHECK_EQUAL(a.GetColumns(), 2);
631
632 using size_type = Array<TwoD, double>::size_type;
633 for (size_type i = 0; i < a.GetRows(); ++i)
634 {
635 for (size_type j = 0; j < a.GetColumns(); ++j)
636 {
637 BOOST_CHECK_EQUAL(a[i][j], a_vals[i * a.GetColumns() + j]);
638 }
639 }
640
641 // Now test assignment.
642 NekDouble rhs_vals[] = {18.0, -76.2, 45.2, 1352.246, -46.346,
643 -2463.346, 26.347, 1.0, 0.0, 23465.3};
644 for (size_type i = 0; i < a.GetRows(); ++i)
645 {
646 for (size_type j = 0; j < a.GetColumns(); ++j)
647 {
648 a[i][j] = rhs_vals[i * a.GetColumns() + j];
649 }
650 }
651
652 for (size_type i = 0; i < a.GetRows(); ++i)
653 {
654 for (size_type j = 0; j < a.GetColumns(); ++j)
655 {
656 BOOST_CHECK_EQUAL(a[i][j], rhs_vals[i * a.GetColumns() + j]);
657 }
658 }
659 }
660
661 {
662 // Test 1 Column.
663 NekDouble a_vals[] = {1.0, 3.0, 5.0, 7.0, 9.0};
664 Array<TwoD, NekDouble> a(5, 1, a_vals);
665 BOOST_CHECK_EQUAL(a.GetRows(), 5);
666 BOOST_CHECK_EQUAL(a.GetColumns(), 1);
667
668 using size_type = Array<TwoD, double>::size_type;
669 for (size_type i = 0; i < a.GetRows(); ++i)
670 {
671 BOOST_CHECK_EQUAL(a[i][0], a_vals[i]);
672 }
673 }
674
675 {
677 a[0][0] = 17.23;
678 BOOST_CHECK_EQUAL(a[0][0], 17.23);
679 }
680}
681
682BOOST_AUTO_TEST_CASE(Test1DEqualOperator)
683{
684 {
685 // integer types
686 using int_type = int;
687
688 int_type a[] = {1, 2, 3, 4, 5};
689
690 Array<OneD, int_type> nek_a(5, a);
691 Array<OneD, int_type> nek_b(5, a);
692 Array<OneD, const int_type> nek_c(5, a);
693
694 // still equal
695 BOOST_CHECK(nek_a == nek_b);
696 // equal and only one const
697 BOOST_CHECK(nek_a == nek_c);
698
699 // not equal
700 nek_b[3] += 1;
701 BOOST_CHECK(!(nek_a == nek_b));
702 }
703
704 {
705 // float types
706 using float_type = double;
707
708 float_type a[] = {1.0, 2.0, 3.0, 4.0, 5.0};
709
710 Array<OneD, float_type> nek_a(5, a);
711 Array<OneD, float_type> nek_b(5, a);
713
714 // still equal
715 nek_b[3] *= (1.0 + std::numeric_limits<float_type>::epsilon());
716 BOOST_CHECK(nek_a == nek_b);
717 // equal and only one const
718 BOOST_CHECK(nek_a == nek_c);
719
720 // not equal
721 nek_b[4] *= (1.0 + 100 * std::numeric_limits<float_type>::epsilon());
722 BOOST_CHECK(!(nek_a == nek_b));
723 }
724
725 // This should not compile
726 // {
727 // // mixed types should not compare
728 // using float_type = double;
729 // using int_type = int;
730
731 // float_type a[] = {1.0, 2.0, 3.0, 4.0, 5.0};
732 // int_type b[] = {1, 2, 3, 4, 5};
733
734 // Array<OneD, float_type> nek_a(5, a);
735 // Array<OneD, int_type> nek_b(5, b);
736
737 // // still equal
738 // BOOST_CHECK(nek_a == nek_b);
739 // }
740}
741
742BOOST_AUTO_TEST_CASE(Test2DEqualOperator)
743{
744 {
745 // integer types
746 using int_type = int;
747
748 int_type a[] = {1, 2, 3, 4, 5};
749 Array<TwoD, int_type> nek_a(5, 1, a);
750 Array<TwoD, int_type> nek_b(5, 1, a);
751 Array<TwoD, const int_type> nek_c(5, 1, a);
752
753 // still equal
754 BOOST_CHECK(nek_a == nek_b);
755 // equal and only one const
756 BOOST_CHECK(nek_a == nek_c);
757
758 // not equal
759 nek_b[3][0] += 1;
760 BOOST_CHECK(!(nek_a == nek_b));
761 }
762
763 {
764 // floating types
765 using float_type = double;
766
767 float_type a[] = {1., 2., 3., 4., 5.};
768 Array<TwoD, float_type> nek_a(5, 1, a);
769 Array<TwoD, float_type> nek_b(5, 1, a);
770 Array<TwoD, const float_type> nek_c(5, 1, a);
771
772 // still equal
773 nek_b[3][0] *= (1.0 + std::numeric_limits<float_type>::epsilon());
774 BOOST_CHECK(nek_a == nek_b);
775 // equal and only one const
776 BOOST_CHECK(nek_a == nek_c);
777
778 // not equal
779 nek_b[4][0] *= (1.0 + 100 * std::numeric_limits<float_type>::epsilon());
780 BOOST_CHECK(!(nek_a == nek_b));
781 }
782}
783
784} // namespace Nektar::SharedArrayUnitTests
static void Check(unsigned int expectedDefaultConstructed, unsigned int expectedConstructedFromInt, unsigned int expectedDestroyed, unsigned int expectedCopied, unsigned int expectedCloned, unsigned int expectedAssigned)
static void ClearCounters()
void getConstByReference(Array< OneD, const NekDouble > &out)
void getNonConstByValue(Array< OneD, NekDouble > out)
void getConstByValue(Array< OneD, const NekDouble > out)
void getNonConstByReference(Array< OneD, NekDouble > &out)
BOOST_AUTO_TEST_CASE(TestArrayConstructionFromConstantArray)
void RedirectCerrIfNeeded()
Definition: util.cpp:41
std::vector< double > d(NPUPPER *NPUPPER)
double NekDouble