Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Assertion.h
Aller à la documentation de ce fichier.
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* Assertion.h (C) 2000-2020 */
9/* */
10/* Ensemble d'assertions utilisées pour les tests unitaires. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13#ifndef ARCANE_ASSERTION_H
14#define ARCANE_ASSERTION_H
15/*---------------------------------------------------------------------------*/
16/*---------------------------------------------------------------------------*/
17
18#include "arcane/utils/TraceInfo.h"
19#include "arcane/utils/Numeric.h"
20#include "arcane/ArcaneTypes.h"
21#include "arcane/ArcaneException.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28class IParallelMng;
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38/*---------------------------------------------------------------------------*/
42class ARCANE_CORE_EXPORT Assertion
43{
44 private:
45
46 void _checkAssertion(bool is_error,const TraceInfo& where,
47 const String& expected, const String& actual, IParallelMng* pm);
48
49 public:
50
51 void fail(const TraceInfo& where)
52 {
53 throw AssertionException(where);
54 }
55
57 void assertTrue(const TraceInfo& where, bool condition, IParallelMng* pm = nullptr)
58 {
59 bool is_error = (!condition);
60 _checkAssertion(is_error, where, "true", "false", pm);
61 }
62
64 void assertFalse(const TraceInfo& where, bool condition, IParallelMng* pm = nullptr)
65 {
66 bool is_error = (condition);
67 _checkAssertion(is_error, where, "false", "true", pm);
68 }
69
74 void assertEqual(const TraceInfo& where, const String& expected,
75 const String& actual, IParallelMng* pm = nullptr)
76 {
77 bool is_error = (expected != actual);
78 _checkAssertion(is_error,where,expected,actual,pm);
79 }
80
81 template<typename T>
82 void assertEqual(const TraceInfo& where, const T& expected, const T& actual, IParallelMng* pm = nullptr)
83 {
84 // utilisation de l'operateur == pour les types numeriques et non !=
85 bool is_error = (! (expected == actual));
86 _checkAssertion(is_error,where,String::fromNumber(expected),String::fromNumber(actual),pm);
87 }
88
89 template<typename T>
90 void assertNearlyEqual(const TraceInfo& where, const T& expected,
91 const T& actual, IParallelMng* pm = nullptr)
92 {
93 bool is_error = (!math::isNearlyEqual(expected,actual));
94 _checkAssertion(is_error,where,String::fromNumber(expected),String::fromNumber(actual),pm);
95 }
96
97 template<typename T>
98 void assertNearlyZero(const TraceInfo& where, const T& actual, IParallelMng* pm = nullptr)
99 {
100 bool is_error = (!math::isNearlyZero(actual));
101 _checkAssertion(is_error, where, "0", String::fromNumber(actual),pm);
102 }
103
104 template<typename T>
105 void assertNearlyEqualWithEpsilon(const TraceInfo& where, const T& expected,
106 const T& actual,const T& epsilon, IParallelMng* pm = nullptr)
107 {
108 bool is_error = (!math::isNearlyEqualWithEpsilon(expected,actual,epsilon));
109 _checkAssertion(is_error, where, String::fromNumber(expected), String::fromNumber(actual), pm);
110 }
111
112 template<typename T>
113 void assertNearlyZeroWithEpsilon(const TraceInfo& where, const T& actual,
114 const T& epsilon, IParallelMng* pm = nullptr)
115 {
116 bool is_error = (!math::isNearlyZeroWithEpsilon(actual,epsilon));
117 _checkAssertion(is_error, where, "0", String::fromNumber(actual), pm);
118 }
119};
120
121#define FAIL fail(A_FUNCINFO)
122
126#define ASSERT_TRUE(condition) \
127assertTrue(A_FUNCINFO, condition)
128
132#define PARALLEL_ASSERT_TRUE(condition, parallel_mng) \
133 assertTrue(A_FUNCINFO, condition, parallel_mng)
134
138#define ASSERT_FALSE(condition) \
139assertFalse(A_FUNCINFO, condition)
140
144#define PARALLEL_ASSERT_FALSE(condition, parallel_mng) \
145 assertFalse(A_FUNCINFO, condition, parallel_mng)
146
151#define ASSERT_EQUAL(expected, actual) \
152assertEqual(A_FUNCINFO, expected, actual)
153
158#define PARALLEL_ASSERT_EQUAL(expected, actual, parallel_mng) \
159 assertEqual(A_FUNCINFO, expected, actual, parallel_mng)
160
165#define ASSERT_NEARLY_EQUAL(expected, actual) \
166assertNearlyEqual(A_FUNCINFO, expected, actual)
167
172#define PARALLEL_ASSERT_NEARLY_EQUAL(expected, actual, parallel_mng) \
173 assertNearlyEqual(A_FUNCINFO, expected, actual, parallel_mng)
174
180#define ASSERT_NEARLY_ZERO(actual) \
181assertNearlyZero(A_FUNCINFO, actual)
182
188#define PARALLEL_ASSERT_NEARLY_ZERO(actual, parallel_mng) \
189 assertNearlyZero(A_FUNCINFO, actual, parallel_mng)
190
195#define ASSERT_NEARLY_EQUAL_EPSILON(expected, actual, epsilon) \
196assertNearlyEqualWithEpsilon(A_FUNCINFO, expected, actual, epsilon)
197
202#define PARALLEL_ASSERT_NEARLY_EQUAL_EPSILON(expected, actual, epsilon, parallel_mng) \
203 assertNearlyEqualWithEpsilon(A_FUNCINFO, expected, actual, epsilon, parallel_mng)
204
210#define ASSERT_NEARLY_ZERO_EPSILON(actual,epsilon) \
211assertNearlyZeroWithEpsilon(A_FUNCINFO, actual, epsilon)
212
218#define PARALLEL_ASSERT_NEARLY_ZERO_EPSILON(actual,epsilon, parallel_mng) \
219 assertNearlyZeroWithEpsilon(A_FUNCINFO, actual, epsilon, parallel_mng)
220
226#define ASSERT_EQUALS(expected, actual) \
227assertEqual(A_FUNCINFO, expected, actual)
228
234#define ASSERT_NEARLY_EQUALS(expected, actual) \
235assertNearlyEqual(A_FUNCINFO, expected, actual)
236
237/*---------------------------------------------------------------------------*/
238/*---------------------------------------------------------------------------*/
239
240} // End namespace Arcane
241
242/*---------------------------------------------------------------------------*/
243/*---------------------------------------------------------------------------*/
244
245#endif
Exception dans une assertion.
Classe de base pour assertions dans les tests unitaires.
Definition Assertion.h:43
void assertTrue(const TraceInfo &where, bool condition, IParallelMng *pm=nullptr)
Lance une exception AssertException si condition est faux.
Definition Assertion.h:57
void assertFalse(const TraceInfo &where, bool condition, IParallelMng *pm=nullptr)
Lance une exception AssertException si condition est vrai.
Definition Assertion.h:64
void assertEqual(const TraceInfo &where, const String &expected, const String &actual, IParallelMng *pm=nullptr)
Definition Assertion.h:74
Interface du gestionnaire de parallélisme pour un sous-domaine.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Chaîne de caractères unicode.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-