Function googletest::matchers::lt

source ·
pub fn lt<ActualT: Debug + PartialOrd<ExpectedT>, ExpectedT: Debug>(
    expected: ExpectedT
) -> impl Matcher<ActualT = ActualT>
Expand description

Matches a value less (in the sense of <) than expected.

The types of ActualT of actual and ExpectedT of expected must be comparable via the PartialOrd trait. Namely, ActualT must implement PartialOrd<ExpectedT>.

verify_that!(1, lt(2))?; // Passes
verify_that!(2, lt(2))?; // Fails

In most cases the params neeed to be the same type or they need to be cast explicitly. This can be surprising when comparing integer types or references:

verify_that!(123u32, lt(0u64))?; // Does not compile
verify_that!(123u32 as u64, lt(100000000u64))?; // Passes
let actual: &u32 = &2;
let expected: u32 = 70;
verify_that!(actual, lt(expected))?; // Does not compile
let actual: &u32 = &2;
let expected: u32 = 70;
verify_that!(actual, lt(&expected))?; // Compiles and passes

You can find the standard library PartialOrd implementation in https://doc.rust-lang.org/core/cmp/trait.PartialOrd.html#implementors