|
micro-test-plus 6.0.0
µTest++ Testing Framework
|
Functions for comparing actual and expected values in tests. More...
Functions | |
| template<class Lhs_T, class Rhs_T, class Epsilon_T> requires (extension::approx_operand<Lhs_T> and extension::approx_operand<Rhs_T> and extension::approx_operand<Epsilon_T>) | |
| constexpr auto | micro_os_plus::micro_test_plus::approx (Lhs_T &&lhs, Rhs_T &&rhs, Epsilon_T &&epsilon) |
| Approximate equality comparator, with an explicit tolerance. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::equal, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::eq (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic equality comparator. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::greater_equal, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::ge (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic greater than or equal comparator. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::greater, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::gt (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic greater than comparator. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::less_equal, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::le (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic less than or equal comparator. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::less, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::lt (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic less than comparator. | |
| template<class Lhs_T, class Rhs_T> requires detail::comparable_operands<detail::comparison::not_equal, Lhs_T, Rhs_T> | |
| constexpr auto | micro_os_plus::micro_test_plus::ne (Lhs_T &&lhs, Rhs_T &&rhs) |
| Generic non-equality comparator. | |
A check written as a plain boolean, such as t.expect (x == 42), reports only its location when it fails. The function comparators compare two values and, when the check fails, also report both values:
| Comparator | True when |
|---|---|
| mt::eq (a, b) | a == b |
| mt::ne (a, b) | a != b |
| mt::lt (a, b) | a < b |
| mt::le (a, b) | a <= b |
| mt::gt (a, b) | a > b |
| mt::ge (a, b) | a >= b |
| mt::approx (a, b, e) | a and b differ by at most e |
When compute_answer() returns 41, the human-readable reporter displays the failed checks with the compared values:
|
nodiscardconstexpr |
The comparison succeeds if the distance between lhs and rhs is less than or equal to epsilon, so a tolerance of zero requires equal values. The operands are numbers, integral or floating-point, possibly of different types (the deprecated value wrappers and numeric literals are also accepted, and their own tolerance is not used). For the integers, the distance is computed exactly, also for operands of different signedness, so approx (0u, -1, 2) succeeds; for the other types, in their common floating-point type. A failure is reported as lhs ~ (rhs +/- epsilon).
The deprecated approx (value, epsilon) form, available only with MICRO_OS_PLUS_MICRO_TEST_PLUS_DEPRECATED_ENABLED, is a value wrapper instead, which applies its tolerance to the six comparisons and to the operators; it accepts only floating-point values.
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| Epsilon_T | Type of the tolerance. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
| epsilon | The tolerance; a negative one fails all comparisons. |
The approx function template constructs a detail::approx_op from the forwarded operands and tolerance; the operands are numbers, so detail::as_operand(), which converts the C strings, is not needed.
Definition at line 306 of file function-comparators-inlines.h.
References approx().
|
nodiscardconstexpr |
The C strings (the arrays, including the string literals, and the pointers of char, wchar_t, char8_t, char16_t, and char32_t) are compared by content, also with the standard strings and string views of the same character type; a null pointer is equal only to another null pointer, and the text of an array ends at its first null character, or at its end. The other arrays (e.g. byte buffers) are compared element by element, also with a container, with the elements compared as the single values are, and written as ranges; the other pointers are compared by address. The integers of different signedness are compared by value, as by std::cmp_equal(), not after the usual arithmetic conversions, so eq (-1, static_cast<unsigned> (-1)) fails; the single characters take part as the integers of the same size and signedness.
Both operands must satisfy extension::printable, since they are reported on failure; an application type needs an operator<< for mt::expression_formatter, otherwise the call is rejected, with a diagnostic that names the operand type. The operands must also be comparable with the operator of the comparator, otherwise the call is rejected in the same way.
The same rules apply to ne(), gt(), ge(), lt(), and le().
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The eq function template provides a generic equality comparator for any types. The operands are first passed to detail::as_operand(), which converts the C strings to detail::basic_c_string, and the other arrays to detail::array_operand, so that they are compared by content. It constructs a comparator object, with the detail::equal_to tag, which evaluates to true if the two values are equal, and which is reported with both values if not.
The operands are forwarded, so that the comparator moves the temporaries, and copies the named operands (see stored_operand_t), so that the expression stays valid after the operands are destroyed, except for the arrays and the C strings, which are referred to.
Definition at line 89 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and eq().
Referenced by eq().
|
nodiscardconstexpr |
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The operands are passed to detail::as_operand(), as for eq(), so that the C strings and the arrays are compared by content. It constructs a comparator object, with the detail::greater_equal tag, which evaluates to true if lhs is greater than or equal to rhs, and which is reported with both values if not.
Definition at line 197 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and ge().
Referenced by ge().
|
nodiscardconstexpr |
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The operands are passed to detail::as_operand(), as for eq(), so that the C strings and the arrays are compared by content. It constructs a comparator object, with the detail::greater tag, which evaluates to true if lhs is greater than rhs, and which is reported with both values if not.
Definition at line 161 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and gt().
Referenced by gt().
|
nodiscardconstexpr |
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The operands are passed to detail::as_operand(), as for eq(), so that the C strings and the arrays are compared by content. It constructs a comparator object, with the detail::less_equal tag, which evaluates to true if lhs is less than or equal to rhs, and which is reported with both values if not.
Definition at line 270 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and le().
Referenced by le().
|
nodiscardconstexpr |
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The operands are passed to detail::as_operand(), as for eq(), so that the C strings and the arrays are compared by content. It constructs a comparator object, with the detail::less tag, which evaluates to true if lhs is less than rhs, and which is reported with both values if not.
Definition at line 234 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and lt().
Referenced by lt().
|
nodiscardconstexpr |
| Lhs_T | Type of the left hand side operand. |
| Rhs_T | Type of the right hand side operand. |
| lhs | Left hand side operand. |
| rhs | Right hand side operand. |
The operands are passed to detail::as_operand(), as for eq(), so that the C strings and the arrays are compared by content. It constructs a comparator object, with the detail::not_equal_to tag, which evaluates to true if the two values are not equal, and which is reported with both values if not.
Definition at line 125 of file function-comparators-inlines.h.
References micro_os_plus::micro_test_plus::detail::as_operand(), and ne().
Referenced by ne().