micro-test-plus 3.2.0
µTest++, a lightweight testing framework for embedded platforms
Loading...
Searching...
No Matches
Function comparators

Functions to compare the actual with expected values. More...

Functions

template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::eq (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic equality comparator. Matches any non-pointer type.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::eq (Lhs_T *lhs, Rhs_T *rhs)
 Pointer equality comparator. Matches pointers to any types.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::ge (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic greater than or equal comparator.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::ge (Lhs_T *lhs, Rhs_T *rhs)
 Pointer greater than or equal comparator.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::gt (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic greater than comparator.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::gt (Lhs_T *lhs, Rhs_T *rhs)
 Pointer greater than comparator.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::le (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic less than or equal comparator.
 
template<class Lhs_T , class 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 >
constexpr auto micro_os_plus::micro_test_plus::lt (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic less than comparator.
 
template<class Lhs_T , class 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 >
constexpr auto micro_os_plus::micro_test_plus::ne (const Lhs_T &lhs, const Rhs_T &rhs)
 Generic non-equality comparator.
 
template<class Lhs_T , class Rhs_T >
constexpr auto micro_os_plus::micro_test_plus::ne (Lhs_T *lhs, Rhs_T *rhs)
 Pointer non-equality comparator.
 

Detailed Description

Functions to compare the actual with expected values.

Expectations and assumptions can test any expression evaluating to a boolean value, but in order to nicely report the difference between expected and actual values in failed conditions, special comparators must be used.

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";

When such comparator functions are used, failed checks also display the actual values compared during the test; for example:

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.000000 != 42.000000))

Comparing containers

Containers can be compared for equality. The comparison is done by iterating and comparing each member.

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 }";

Function Documentation

◆ eq() [1/2]

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

Generic equality comparator. Matches any non-pointer type.

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
True if the operands are equal.

Definition at line 237 of file micro-test-plus.h.

◆ eq() [2/2]

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

Pointer equality comparator. Matches pointers to any 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
True if the pointers are equal.

Definition at line 254 of file micro-test-plus.h.

◆ ge() [1/2]

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

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
True if lhs >= rhs.

Definition at line 334 of file micro-test-plus.h.

◆ ge() [2/2]

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

Pointer 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
True if the lhs pointer >= rhs pointer.

Definition at line 350 of file micro-test-plus.h.

◆ gt() [1/2]

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

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
True if lhs > rhs.

Definition at line 302 of file micro-test-plus.h.

◆ gt() [2/2]

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

Pointer 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
True if the lhs pointer > rhs pointer.

Definition at line 318 of file micro-test-plus.h.

◆ le() [1/2]

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

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
True if lhs <= rhs.

Definition at line 398 of file micro-test-plus.h.

◆ le() [2/2]

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

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
True if the lhs pointer <= rhs pointer.

Definition at line 414 of file micro-test-plus.h.

◆ lt() [1/2]

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

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
True if lhs < rhs.

Definition at line 366 of file micro-test-plus.h.

◆ lt() [2/2]

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

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
True if the lhs pointer < rhs pointer.

Definition at line 382 of file micro-test-plus.h.

◆ ne() [1/2]

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

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
True if the operands are not equal.

Definition at line 270 of file micro-test-plus.h.

◆ ne() [2/2]

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

Pointer 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
True if the pointers are not equal.

Definition at line 286 of file micro-test-plus.h.