use crate::{
MatchType::{self, ToBe},
Matcher, TypedMatcher,
};
use std::fmt::Debug;
pub fn gt<T>(value: T) -> GreaterThan<T> {
GreaterThan(value)
}
pub struct GreaterThan<T>(T);
impl<T> Matcher<T> for GreaterThan<T>
where
T: PartialOrd + Debug,
{
fn matches(&self, value: &T) -> bool {
*value > self.0
}
fn description(&self) -> String {
format!("greater than {:?}", self.0)
}
}
impl<T> TypedMatcher<T> for GreaterThan<T>
where
T: PartialOrd + Debug,
{
fn matcher_type(&self) -> MatchType {
ToBe
}
}
pub fn ge<T>(value: T) -> GreaterThanOrEqual<T> {
GreaterThanOrEqual(value)
}
pub struct GreaterThanOrEqual<T>(T);
impl<T> Matcher<T> for GreaterThanOrEqual<T>
where
T: PartialOrd + Debug,
{
fn matches(&self, value: &T) -> bool {
*value >= self.0
}
fn description(&self) -> String {
format!("greater than or equal to {:?}", self.0)
}
}
impl<T> TypedMatcher<T> for GreaterThanOrEqual<T>
where
T: PartialOrd + Debug,
{
fn matcher_type(&self) -> MatchType {
ToBe
}
}