[][src]Struct exonum_testkit::compare::Comparison

pub struct Comparison<T> { /* fields omitted */ }

Facilitation of comparison between 2 states.

Methods

impl<T> Comparison<T>[src]

pub fn new(old: T, new: T) -> Self[src]

Creates a comparison between 2 states.

pub fn map<'a, F, U>(&'a self, f: F) -> Comparison<U> where
    F: Fn(&'a T) -> U, 
[src]

Maps this comparison to another type of objects.

Examples

let comparison = Comparison::new(vec![1, 2, 3], vec![4, 5])
    .map(Vec::len);
// Now, this is a comparison between `3` and `2`

pub fn assert_before<P>(&self, message: &str, predicate: P) -> &Self where
    P: Fn(&T) -> bool
[src]

Asserts a statement about the older state in this comparison.

Panics

  • Panics if the statement does not hold.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5])
    .map(Vec::len)
    .assert_before("Array length <= 5", |&len| len <= 5);

pub fn assert_after<P>(&self, message: &str, predicate: P) -> &Self where
    P: Fn(&T) -> bool
[src]

Asserts a statement about the newer state in this comparison.

Panics

  • Panics if the statement does not hold.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5])
    .assert_after("The second element is greater than first", |v| {
        v[1] > v[0]
    });

pub fn assert<P>(&self, message: &str, predicate: P) -> &Self where
    P: Fn(&T, &T) -> bool
[src]

Asserts a statement about the both states in this comparison.

Panics

  • Panics if the statement does not hold.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5])
    .map(Vec::len)
    .assert("Less elements after", |&old, &new| old > new);

pub fn assert_inv<P>(&self, message: &str, predicate: P) -> &Self where
    P: Fn(&T) -> bool
[src]

Asserts a statement that should hold true for both states in this comparison.

Panics

  • Panics if the statement does not hold for either of states.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5])
    .map(Vec::len)
    .assert_inv("More than 1 element in array", |&len| len > 1);

impl<T: PartialEq + Debug> Comparison<T>[src]

pub fn assert_eq(&self, message: &str) -> &Self[src]

Asserts that the states are equal (by the PartialEq definition).

Panics

  • Panics if the states are not equal.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5, 6])
    .map(Vec::len)
    .assert_eq("Array length doesn't change");

pub fn assert_ne(&self, message: &str) -> &Self[src]

Asserts that the states are equal (by the PartialEq definition).

Panics

  • Panics if the states are equal.

Examples

Comparison::new(vec![1, 2, 3], vec![4, 5])
    .map(Vec::len)
    .assert_ne("Array length should change");

Trait Implementations

impl<T: Debug> Debug for Comparison<T>[src]

Auto Trait Implementations

impl<T> Send for Comparison<T> where
    T: Send

impl<T> Sync for Comparison<T> where
    T: Sync

Blanket Implementations

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> From for T[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T> Same for T

type Output = T

Should always be Self