Skip to main content

The Function Comparators Reference

Functions for comparing actual and expected values in tests. More...

Functions Index

constexpr autoeq (const Lhs_T &lhs, const Rhs_T &rhs)

Generic equality comparator for non-pointer types. More...

constexpr autoeq (Lhs_T *lhs, Rhs_T *rhs)

Pointer equality comparator for any pointer types. More...

constexpr autoge (const Lhs_T &lhs, const Rhs_T &rhs)

Generic greater than or equal comparator. More...

constexpr autoge (Lhs_T *lhs, Rhs_T *rhs)

Pointer greater than or equal comparator. More...

constexpr autogt (const Lhs_T &lhs, const Rhs_T &rhs)

Generic greater than comparator. More...

constexpr autogt (Lhs_T *lhs, Rhs_T *rhs)

Pointer greater than comparator. More...

constexpr autole (const Lhs_T &lhs, const Rhs_T &rhs)

Generic less than or equal comparator. More...

constexpr autole (Lhs_T *lhs, Rhs_T *rhs)

Pointer less than or equal comparator. More...

constexpr autolt (const Lhs_T &lhs, const Rhs_T &rhs)

Generic less than comparator. More...

constexpr autolt (Lhs_T *lhs, Rhs_T *rhs)

Pointer less than comparator. More...

constexpr autone (const Lhs_T &lhs, const Rhs_T &rhs)

Generic non-equality comparator. More...

constexpr autone (Lhs_T *lhs, Rhs_T *rhs)

Pointer non-equality comparator. More...

Description

Function comparators in µTest++ provide a clear and expressive way to compare actual and expected values within test cases. While any expression yielding a boolean value may be used in expectations and assumptions, dedicated comparator functions such as eq, ne, lt, le, gt, and ge offer enhanced reporting by explicitly showing the values involved when a check fails.

Using these comparators ensures that, in the event of a failed check, the test output will include both the actual and expected values, making it easier to diagnose issues and understand the cause of the failure.

Comparators are available for both fundamental types and standard containers. When comparing containers, each element is assessed individually, and the results are reported in detail.

Examples
 mt::expect (mt::eq (compute_answer (), 42)) << "answer is 42";
 mt::expect (mt::ne (compute_answer (), 43)) << "answer is not 43";
 mt::expect (mt::lt (compute_answer (), 43)) << "answer is < 43";
 mt::expect (mt::le (compute_answer (), 43)) << "answer is <= 42";
 mt::expect (mt::gt (compute_answer (), 41)) << "answer is > 43";
 mt::expect (mt::ge (compute_answer (), 42)) << "answer is >= 42";
 
 mt::expect (compute_condition ()) << "condition is true";

If a comparator check fails, the output will clearly indicate the actual and expected values:

  Check failed comparisons
  ✗ actual != 42 FAILED (unit-test.cpp:286, 42 != 42)
  ✗ FAILED (unit-test.cpp:307, 42 != 42)
  ✗ 42 != 42_i FAILED (unit-test.cpp:310, 42 != 42)
  ✗ (actual == 42) and (actual != 42.0) FAILED (unit-test.cpp:781, (42 == 42
 and 42 != 42.000000))

Comparing containers

Containers can be compared for equality or inequality using the same comparator functions. The comparison is performed by iterating through each element and evaluating them individually.

Examples
 mt::expect (mt::eq (std::vector<int>{ 1, 2 }, std::vector<int>{ 1, 2 }))
  << "vector{ 1, 2 } eq vector{ 1, 2 }";
 
 mt::expect (mt::ne (std::vector<int>{ 1, 2, 3 }, std::vector<int>{ 1, 2, 4 })
  << "vector{ 1, 2, 3 } ne vector{ 1, 2, 4 }";

Functions

eq()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::eq (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic equality comparator for non-pointer types.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the operands are equal.

The eq function template provides a generic equality comparator for any non-pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that two values are equal. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 85 of file function-comparators-inlines.h.

eq()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::eq (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer equality comparator for any pointer types.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the pointers are equal.

The eq function template provides a pointer equality comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that two pointers are equal. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 100 of file function-comparators-inlines.h.

ge()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::ge (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic greater than or equal comparator.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if lhs is greater than or equal to rhs.

The ge function template provides a generic greater than or equal comparator for any types. It constructs a comparator object that can be used within the µTest++ framework to assert that one value is greater than or equal to another. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 175 of file function-comparators-inlines.h.

ge()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::ge (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer greater than or equal comparator.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the left hand side pointer is greater than or equal to the right hand side pointer.

The ge function template provides a pointer greater than or equal comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that one pointer is greater than or equal to another. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 191 of file function-comparators-inlines.h.

gt()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::gt (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic greater than comparator.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if lhs is greater than rhs.

The gt function template provides a generic greater than comparator for any types. It constructs a comparator object that can be used within the µTest++ framework to assert that one value is greater than another. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 145 of file function-comparators-inlines.h.

gt()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::gt (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer greater than comparator.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the left hand side pointer is greater than the right hand side pointer.

The gt function template provides a pointer greater than comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that one pointer is greater than another. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 160 of file function-comparators-inlines.h.

le()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::le (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic less than or equal comparator.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if lhs is less than or equal to rhs.

The le function template provides a generic less than or equal comparator for any types. It constructs a comparator object that can be used within the µTest++ framework to assert that one value is less than or equal to another. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 236 of file function-comparators-inlines.h.

le()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::le (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer less than or equal comparator.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the left hand side pointer is less than or equal to the right hand side pointer.

The le function template provides a pointer less than or equal comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that one pointer is less than or equal to another. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 252 of file function-comparators-inlines.h.

lt()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::lt (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic less than comparator.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if lhs is less than rhs.

The lt function template provides a generic less than comparator for any types. It constructs a comparator object that can be used within the µTest++ framework to assert that one value is less than another. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 206 of file function-comparators-inlines.h.

lt()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::lt (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer less than comparator.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the left hand side pointer is less than the right hand side pointer.

The lt function template provides a pointer less than comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that one pointer is less than another. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 221 of file function-comparators-inlines.h.

ne()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::ne (const Lhs_T & lhs, const Rhs_T & rhs)
nodiscardconstexpr

Generic non-equality comparator.

Template Parameters
Lhs_TType of the left hand side operand.
Rhs_TType of the right hand side operand.
Parameters
[in] lhsLeft hand side operand.
[in] rhsRight hand side operand.
Returns

A comparator object that evaluates to true if the operands are not equal.

The ne function template provides a generic non-equality comparator for any types. It constructs a comparator object that can be used within the µTest++ framework to assert that two values are not equal. This function is typically used in test expectations and assertions to compare the actual and expected values.

Definition at line 115 of file function-comparators-inlines.h.

ne()

template <class Lhs_T, class Rhs_T>
auto micro_os_plus::micro_test_plus::ne (Lhs_T * lhs, Rhs_T * rhs)
nodiscardconstexpr

Pointer non-equality comparator.

Template Parameters
Lhs_TType of the left hand side pointer operand.
Rhs_TType of the right hand side pointer operand.
Parameters
[in] lhsLeft hand side pointer operand.
[in] rhsRight hand side pointer operand.
Returns

A comparator object that evaluates to true if the pointers are not equal.

The ne function template provides a pointer non-equality comparator for any pointer types. It constructs a comparator object that can be used within the µTest++ framework to assert that two pointers are not equal. This function is typically used in test expectations and assertions to compare the addresses of objects or resources.

Definition at line 130 of file function-comparators-inlines.h.


Generated via docusaurus-plugin-doxygen by Doxygen 1.14.0.