micro-test-plus 4.1.0
µTest++ Testing Framework
Loading...
Searching...
No Matches

Overloaded operators for expressive test comparisons. More...

Functions

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator and (const Lhs_T &lhs, const Rhs_T &rhs)
 Logical && (and) operator. Matches only if at least one operand is of local type (derived from local op).
template<class T>
requires type_traits::is_op<T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator not (const T &t)
 Logical ! (not) operator. Matches only if the operand is of local type (derived from local op).
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator or (const Lhs_T &lhs, const Rhs_T &rhs)
 Logical || (or) operator. Matches only if at least one operand is of local type (derived from local op).
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator!= (const Lhs_T &lhs, const Rhs_T &rhs)
 Non-equality operator for custom types. Matches only if at least one operand is of local type.
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator< (const Lhs_T &lhs, const Rhs_T &rhs)
 Less than operator. Matches only if at least one operand is of local type (derived from local op).
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator<= (const Lhs_T &lhs, const Rhs_T &rhs)
 Less than or equal operator. Matches only if at least one operand is of local type (derived from local op).
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator== (const Lhs_T &lhs, const Rhs_T &rhs)
 Equality operator for custom types. Matches only if at least one operand is of local type.
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator> (const Lhs_T &lhs, const Rhs_T &rhs)
 Greater than operator. Matches only if at least one operand is of local type (derived from local op).
template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
constexpr auto micro_os_plus::micro_test_plus::operators::operator>= (const Lhs_T &lhs, const Rhs_T &rhs)
 Greater than or equal operator. Matches only if at least one operand is of local type (derived from local op).

Detailed Description

These overloads enable expressive, type-safe test assertions. Operators such as ==, !=, <, >, <=, and >= are defined in the dedicated micro_test_plus::operators namespace to avoid conflicts with application-defined operators.

For standard values, the default operators are used, ensuring correct comparisons. However, when specialised µTest++ operators are used with typed operands, failed checks display both actual and expected values, greatly improving report clarity.

These operators are restricted to operands derived from the local detail::op type. For constant values, this is achieved with provided literals (for example, 1_i), whilst dynamic values can be wrapped with converters such as mt::to_i{expression}.

Logical operators (&&, ||, !) are also supported and provide enhanced functionality when used with typed operands, allowing complex test conditions to be composed naturally and readably.

Examples
ts.test ("Operators", [] (auto& t) {
using namespace micro_test_plus::operators;
using namespace micro_test_plus::literals;
t.expect (compute_answer () == 42_i) << "answer is 42 (with literal)";
t.expect (mt::to_i {compute_answer ()} == 42) << "answer is 42 (with cast)";
t.expect (compute_answer () != 43_i) << "answer is not 43";
t.expect (compute_answer () < 43_i) << "answer is < 43";
t.expect (compute_answer () <= 43_i) << "answer is <= 43";
t.expect (compute_answer () > 41_i) << "answer is > 41";
t.expect (compute_answer () >= 42_i) << "answer is >= 42";
});
Logical Operators

Logical operators provide enhanced reporting when used with typed operands, allowing complex test conditions to be composed naturally and readably.

Example
ts.test ("Logical operators", [] (auto& t) {
using namespace micro_test_plus::operators;
using namespace micro_test_plus::literals;
t.expect (compute_answer () == 42_i && compute_float () == 42.0_f);
});

Function Documentation

◆ operator and()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator and ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an and_ logical conjunction object from the two operands and returns it. The object evaluates to true if both operands are true. At least one operand must derive from the local op base.

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 logical conjunction object that evaluates to true if both operands are true.

Definition at line 224 of file operators-inlines.h.

225 {
226 return detail::and_{ lhs, rhs };
227 }
Logical AND comparator struct template.
Definition detail.h:503

◆ operator not()

template<class T>
requires type_traits::is_op<T>
auto micro_os_plus::micro_test_plus::operators::operator not ( const T & t)
nodiscardconstexpr

Constructs a not_ logical negator object from the operand and returns it. The object evaluates to true if the operand is false. The operand must derive from the local op base.

Template Parameters
TType of the operand, constrained to types derived from the local op base.
Parameters
[in]tOperand to be logically negated.
Returns
A logical negator object that evaluates to true if the operand is false.

Definition at line 252 of file operators-inlines.h.

253 {
254 return detail::not_{ t };
255 }
Logical NOT comparator struct template.
Definition detail.h:567

◆ operator or()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator or ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an or_ logical disjunction object from the two operands and returns it. The object evaluates to true if at least one operand is true. At least one operand must derive from the local op base.

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 logical disjunction object that evaluates to true if at least one operand is true.

Definition at line 238 of file operators-inlines.h.

239 {
240 return detail::or_{ lhs, rhs };
241 }
Logical OR comparator struct template.
Definition detail.h:536

◆ operator!=()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator!= ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an ne_ comparator object from the two operands and returns it. The comparator evaluates to true if the operands are not equal. At least one operand must derive from the local op base.

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.

Definition at line 152 of file operators-inlines.h.

153 {
154 return detail::ne_{ lhs, rhs };
155 }
Non-equality comparator struct template.
Definition detail.h:338

◆ operator<()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator< ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an lt_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is less than rhs. At least one operand must derive from the local op base.

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 left hand side operand is less than the right hand side operand.

Definition at line 194 of file operators-inlines.h.

196 {
197 return detail::lt_{ lhs, rhs };
198 }
Less than comparator struct template.
Definition detail.h:436

◆ operator<=()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator<= ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an le_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is less than or equal to rhs. At least one operand must derive from the local op base.

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 left hand side operand is less than or equal to the right hand side operand.

Definition at line 209 of file operators-inlines.h.

211 {
212 return detail::le_{ lhs, rhs };
213 }
Less than or equal comparator struct template.
Definition detail.h:469

◆ operator==()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator== ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs an eq_ comparator object from the two operands and returns it. The comparator evaluates to true if the operands are equal. At least one operand must derive from the local op base.

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.

Definition at line 138 of file operators-inlines.h.

139 {
140 return detail::eq_{ lhs, rhs };
141 }
Equality comparator struct template.
Definition detail.h:306

◆ operator>()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator> ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs a gt_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is greater than rhs. At least one operand must derive from the local op base.

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 left hand side operand is greater than the right hand side operand.

Definition at line 166 of file operators-inlines.h.

167 {
168 return detail::gt_{ lhs, rhs };
169 }
Greater than comparator struct template.
Definition detail.h:370

◆ operator>=()

template<class Lhs_T, class Rhs_T>
requires type_traits::any_op<Lhs_T, Rhs_T>
auto micro_os_plus::micro_test_plus::operators::operator>= ( const Lhs_T & lhs,
const Rhs_T & rhs )
nodiscardconstexpr

Constructs a ge_ comparator object from the two operands and returns it. The comparator evaluates to true if lhs is greater than or equal to rhs. At least one operand must derive from the local op base.

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 left hand side operand is greater than or equal to the right hand side operand.

Definition at line 181 of file operators-inlines.h.

182 {
183 return detail::ge_{ lhs, rhs };
184 }
Greater than or equal comparator struct template.
Definition detail.h:403