12#ifndef ARCANE_UTILS_VALUECHECKER_H
13#define ARCANE_UTILS_VALUECHECKER_H
18#include "arcane/utils/OStringStream.h"
19#include "arcane/utils/TraceInfo.h"
41class ARCANE_UTILS_EXPORT ValueChecker
48 , m_throw_on_error(
true)
56 template <
typename T1,
typename T2,
typename X = std::is_convertible<T2, T1>>
57 void areEqual(
const T1& value,
const T2& expected_value,
const String& message)
59 if (value != expected_value) {
60 _addError(String::format(
"{0} value={1} expected={2}", message, value, expected_value));
68 template <
typename T1,
typename T2,
69 typename ValueType =
typename T1::value_type,
70 typename X1 = std::is_convertible<T1, Span<const ValueType>>,
71 typename X2 = std::is_convertible<T1, Span<const ValueType>>>
78 Int64 nb_value = values.size();
79 Int64 nb_expected = expected_values.
size();
80 if (nb_value != nb_expected) {
81 _addError(String::format(
"{0} bad array size n={1} expected={2}",
82 message, nb_value, nb_expected));
88 for (
Int64 i = 0; i < nb_value; ++i) {
92 _addError(String::format(
"{0} index={1} value={2} expected={3}", message, i, v, e));
101 template <
typename T>
107 if (nb_value != nb_expected) {
108 _addError(String::format(
"{0} bad array size n={1} expected={2}",
109 message, nb_value, nb_expected));
115 for (
Int64 i = 0; i < nb_value; ++i)
123 template <
typename T>
138 m_throw_on_error = v;
153 bool m_throw_on_error;
157 void _addError(
const String& message);
Declarations of types used in Arcane.
Output stream linked to a String.
View for a 2D array whose size is an 'Int32'.
constexpr __host__ __device__ SizeType dim1Size() const
Number of elements in the first dimension.
View for a 2D array whose size is an 'Int64'.
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.
void areEqual(const T1 &value, const T2 &expected_value, const String &message)
void areEqualArray(const T1 &x_values, const T2 &x_expected_values, const String &message)
Checks that the two arrays values and expected_values have the same values.
void areEqualArray(SmallSpan2< T > values, SmallSpan2< T > expected_values, const String &message)
Checks that the two arrays values and expected_values have the same values.
bool throwOnError() const
Indicates whether an exception is thrown in case of an error.
void areEqualArray(Span2< const T > values, Span2< const T > expected_values, const String &message)
Checks that the two 2D arrays values and expected_values have the same values.
Integer nbError() const
Number of errors.
void setThrowOnError(bool v)
Indicates whether an exception is thrown in case of an error.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.