Struct arithmetic_eval::fns::AssertClose
source · pub struct AssertClose<T> { /* private fields */ }
Expand description
Assertion that two values are close to each other.
Unlike AssertEq
, the arguments must be primitive. The function is parameterized by
the tolerance threshold.
§Type
(using arithmetic-typing
notation)
(Num, Num) -> ()
§Examples
let program = "
assert_close(sqrt(9), 3); // this assertion is fine
assert_close(sqrt(10), 3); // this one should fail
";
let module = Untyped::<F32Grammar>::parse_statements(program)?;
let module = ExecutableModule::new("test_assert", &module)?;
let mut env = Environment::new();
env.insert_native_fn("assert_close", fns::AssertClose::new(1e-4))
.insert_wrapped_fn("sqrt", f32::sqrt);
let err = module.with_env(&env)?.run().unwrap_err();
assert_eq!(
err.source().location().in_module().span(program),
"assert_close(sqrt(10), 3)"
);
Implementations§
source§impl<T> AssertClose<T>
impl<T> AssertClose<T>
Trait Implementations§
source§impl<T: Clone> Clone for AssertClose<T>
impl<T: Clone> Clone for AssertClose<T>
source§fn clone(&self) -> AssertClose<T>
fn clone(&self) -> AssertClose<T>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T: Debug> Debug for AssertClose<T>
impl<T: Debug> Debug for AssertClose<T>
source§impl<T: Clone + Display> NativeFn<T> for AssertClose<T>
impl<T: Clone + Display> NativeFn<T> for AssertClose<T>
source§fn evaluate(
&self,
args: Vec<SpannedValue<T>>,
ctx: &mut CallContext<'_, T>,
) -> EvalResult<T>
fn evaluate( &self, args: Vec<SpannedValue<T>>, ctx: &mut CallContext<'_, T>, ) -> EvalResult<T>
Executes the function on the specified arguments.
impl<T: Copy> Copy for AssertClose<T>
Auto Trait Implementations§
impl<T> Freeze for AssertClose<T>where
T: Freeze,
impl<T> RefUnwindSafe for AssertClose<T>where
T: RefUnwindSafe,
impl<T> Send for AssertClose<T>where
T: Send,
impl<T> Sync for AssertClose<T>where
T: Sync,
impl<T> Unpin for AssertClose<T>where
T: Unpin,
impl<T> UnwindSafe for AssertClose<T>where
T: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)