Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
TestRealN.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2024 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7
8#include <gtest/gtest.h>
9
10#include "arcane/utils/ValueConvert.h"
11#include "arcane/utils/NumericTypes.h"
12
13#include <type_traits>
14
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18using namespace Arcane;
19
20TEST(TestRealN,Real2)
21{
22 {
23 Real2 v1;
24 ASSERT_EQ(v1.x,0.0);
25 ASSERT_EQ(v1.y,0.0);
26 }
27 {
28 double value = 0.2;
29 Real2 v1(value);
30 ASSERT_EQ(v1.x,value);
31 ASSERT_EQ(v1.y,value);
32 Real2 v2(v1);
33 ASSERT_EQ(v2.x,value);
34 ASSERT_EQ(v2.y,value);
35 v2.x = 3.5;
36 v2.y = 1.2;
37 v1 = v2;
38 ASSERT_EQ(v1.x,3.5);
39 ASSERT_EQ(v1.y,1.2);
40 ASSERT_EQ(v1,v2);
41 }
42 {
43 double value = 0.3;
44 Real2 v2;
45 v2 = value;
46 ASSERT_EQ(v2.x,value);
47 ASSERT_EQ(v2.x,value);
48 }
49 // Operator + and -
50 {
51 Real2 v2(1.2,4.5);
52 Real2 v1(1.3,2.3);
53 Real2 v3 = v1 + v2;
54 ASSERT_EQ(v3.x,2.5);
55 ASSERT_EQ(v3.y,6.8);
56 Real2 v4 = v3 - v2;
57 ASSERT_EQ(v4,v1);
58 }
59 // Operator * and /
60 {
61 Real2 v2(1.2,4.5);
62 Real2 v1(1.3,2.3);
63 Real2 v3 = v1 * v2;
64 ASSERT_EQ(v3.x,1.2*1.3);
65 ASSERT_EQ(v3.y,4.5*2.3);
66 Real2 v4 = v3 * 2.3;
67 ASSERT_EQ(v4.x,v3.x*2.3);
68 ASSERT_EQ(v4.y,v3.y*2.3);
69 Real2 v5 = v4 / 2.4;
70 ASSERT_EQ(v5.x,v4.x/2.4);
71 ASSERT_EQ(v5.y,v4.y/2.4);
72 }
73 {
74 Real3 v3(1.2,2.3,4.5);
75 Real2 v2(v3);
76 ASSERT_EQ(v2.x,1.2);
77 ASSERT_EQ(v2.y,2.3);
78 }
79}
80
81TEST(TestRealN,Real3)
82{
83 {
84 Real3 v1;
85 ASSERT_EQ(v1.x,0.0);
86 ASSERT_EQ(v1.y,0.0);
87 ASSERT_EQ(v1.z,0.0);
88 }
89 {
90 double value = 0.2;
91 Real3 v1(value);
92 ASSERT_EQ(v1.x,value);
93 ASSERT_EQ(v1.y,value);
94 ASSERT_EQ(v1.z,value);
95 Real3 v2(v1);
96 ASSERT_EQ(v2.x,value);
97 ASSERT_EQ(v2.y,value);
98 ASSERT_EQ(v2.z,value);
99 v2.x = 3.5;
100 v2.y = 1.2;
101 v2.z = -1.5;
102 v1 = v2;
103 ASSERT_EQ(v1.x,3.5);
104 ASSERT_EQ(v1.y,1.2);
105 ASSERT_EQ(v1.z,-1.5);
106 ASSERT_EQ(v1,v2);
107 }
108 {
109 Real2 v2(1.2,2.3);
110 Real3 v3(v2);
111 ASSERT_EQ(v3.x,1.2);
112 ASSERT_EQ(v3.y,2.3);
113 ASSERT_EQ(v3.z,0.0);
114 }
115}
116
117TEST(TestRealN,Real2x2)
118{
119 Real2 zero;
120 {
121 Real2x2 v1;
122 ASSERT_EQ(v1.x,zero);
123 ASSERT_EQ(v1.y,zero);
124 }
125 {
126 double value = 0.2;
127 Real2 r2_value(value);
128 Real2x2 v1(value);
129 ASSERT_EQ(v1.x,r2_value);
130 ASSERT_EQ(v1.y,r2_value);
131 Real2x2 v2(v1);
132 ASSERT_EQ(v2.x,v1.x);
133 ASSERT_EQ(v2.y,v1.y);
134 Real2 rx(3.5, 1.2);
135 Real2 ry(1.6, 2.1);
136 v2.x = rx;
137 v2.y = ry;
138 v1 = v2;
139 ASSERT_EQ(v1.x,rx);
140 ASSERT_EQ(v1.y,ry);
141 ASSERT_EQ(v1,v2);
142 }
143}
144
145TEST(TestRealN,Real3x3)
146{
147 Real3 zero;
148 {
149 Real3x3 v1;
150 ASSERT_EQ(v1.x,zero);
151 ASSERT_EQ(v1.y,zero);
152 ASSERT_EQ(v1.z,zero);
153 }
154 {
155 double value = 0.2;
156 Real3 r3_value(value);
157 Real3x3 v1(value);
158 ASSERT_EQ(v1.x,r3_value);
159 ASSERT_EQ(v1.y,r3_value);
160 ASSERT_EQ(v1.z,r3_value);
161 Real3x3 v2(v1);
162 ASSERT_EQ(v2.x,v1.x);
163 ASSERT_EQ(v2.y,v1.y);
164 ASSERT_EQ(v2.z,v1.z);
165 Real3 rx(3.5, 1.2, -1.5);
166 Real3 ry(1.6, 2.1, -2.3);
167 Real3 rz(-2.3, 1.8, 9.4);
168 v2.x = rx;
169 v2.y = ry;
170 v2.z = rz;
171 v1 = v2;
172 ASSERT_EQ(v1.x,rx);
173 ASSERT_EQ(v1.y,ry);
174 ASSERT_EQ(v1.z,rz);
175 ASSERT_EQ(v1,v2);
176 }
177}
178
180{
181 ASSERT_TRUE(std::is_trivially_copyable_v<Real2>);
182 ASSERT_TRUE(std::is_trivially_copyable_v<Real3>);
183 ASSERT_TRUE(std::is_trivially_copyable_v<Real2x2>);
184 ASSERT_TRUE(std::is_trivially_copyable_v<Real3x3>);
185}
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
#define ASSERT_TRUE(condition)
Vérifie que condition est vrai.
Definition Assertion.h:126
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Classe gérant un vecteur de réel de dimension 2.
Definition Real2.h:121
Classe gérant une matrice de réel de dimension 2x2.
Definition Real2x2.h:53
Real2 x
Première composante.
Definition Real2x2.h:98
Real2 y
Deuxième composante.
Definition Real2x2.h:99
Classe gérant un vecteur de réel de dimension 3.
Definition Real3.h:132
Classe gérant une matrice de réel de dimension 3x3.
Definition Real3x3.h:66
Real3 z
premier élément du triplet
Definition Real3x3.h:119
Real3 y
premier élément du triplet
Definition Real3x3.h:118
Real3 x
premier élément du triplet
Definition Real3x3.h:117
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Real y
deuxième composante du couple
Definition Real2.h:35
Real x
première composante du couple
Definition Real2.h:34
Real y
deuxième composante du triplet
Definition Real3.h:36
Real z
troisième composante du triplet
Definition Real3.h:37
Real x
première composante du triplet
Definition Real3.h:35