mod eq;
mod error;
mod fd;
mod fd_eq;
#[cfg(test)]
mod test;
pub use self::{eq::AssertEq, error::AssertionError, fd::FiniteDifference, fd_eq::AssertFd};
use self::eq::{zero_impl, zero_within_tols_impl};
use crate::{
ABS_TOL, EPSILON, REL_TOL,
math::{Scalar, Tensor},
};
use std::fmt::Display;
pub struct Assert {
pub abs_tol: Scalar,
pub rel_tol: Scalar,
pub fd_tol: Scalar,
}
impl Default for Assert {
fn default() -> Self {
Self {
abs_tol: ABS_TOL,
rel_tol: REL_TOL,
fd_tol: 3.0 * EPSILON,
}
}
}
impl Assert {
pub fn eq<T, Rhs>(a: T, b: Rhs) -> Result<(), AssertionError>
where
T: AssertEq<Rhs>,
{
T::eq(a, b)
}
pub fn eq_within_tols<T, Rhs>(&self, a: T, b: Rhs) -> Result<(), AssertionError>
where
T: AssertEq<Rhs>,
{
T::eq_within_tols(self, a, b)
}
pub fn eq_within_fd_tol<T, Rhs>(&self, a: T, b: Rhs) -> Result<(), AssertionError>
where
T: AssertFd<Rhs>,
{
T::eq_within_fd_tol(self, a, b)
}
pub fn zero<T>(a: &T) -> Result<(), AssertionError>
where
T: Display + Tensor,
{
zero_impl(a)
}
pub fn zero_within_tols<T>(&self, a: &T) -> Result<(), AssertionError>
where
T: Display + Tensor,
{
zero_within_tols_impl(self, a)
}
}