#testing #arrays #float

russell_chk

Functions to check vectors and other data in tests

6 releases

0.2.1 Oct 23, 2021
0.2.0 Oct 22, 2021
0.1.3 Oct 7, 2021
0.1.2 Sep 19, 2021
0.1.0 Jun 22, 2021

#263 in Math

Download history 18/week @ 2022-02-28 16/week @ 2022-03-07 36/week @ 2022-03-14 25/week @ 2022-03-21 24/week @ 2022-03-28 16/week @ 2022-04-04 13/week @ 2022-04-11 11/week @ 2022-04-18 52/week @ 2022-04-25 70/week @ 2022-05-02 56/week @ 2022-05-09 125/week @ 2022-05-16 48/week @ 2022-05-23 117/week @ 2022-05-30 36/week @ 2022-06-06 14/week @ 2022-06-13

225 downloads per month
Used in fewer than 8 crates

MIT license

21KB
357 lines

Russell Chk - Functions to check vectors and other data in tests

This crate is part of Russell - Rust Scientific Library

This repository implements macros to assist in tests (numerical checks).

Documentation:

Installation

Add this to your Cargo.toml:

[dependencies]
russell_chk = "*"

Examples

Check float point numbers

use russell_chk::*;

fn main() {
    assert_approx_eq!(0.123456789, 0.12345678, 1e-8);
    assert_approx_eq!(0.123456789, 0.1234567, 1e-7);
    assert_approx_eq!(0.123456789, 0.123456, 1e-6);
    assert_approx_eq!(0.123456789, 0.12345, 1e-5);
    assert_approx_eq!(0.123456789, 0.1234, 1e-4);
}

Check a vector of float point numbers

use russell_chk::*;

fn main() {
    let a = [0.123456789, 0.123456789, 0.123456789];
    let b = [0.12345678,  0.1234567,   0.123456];
    assert_vec_approx_eq!(&a, &b, 1e-6);
}

Check derivatives

use russell_chk::*;

struct Arguments {}

fn main() {
    let f = |x: f64, _: &mut Arguments| -x;
    let args = &mut Arguments {};
    let at_x = 8.0;
    let dfdx = -1.01;
    assert_deriv_approx_eq!(dfdx, at_x, f, args, 1e-2);
}

No runtime deps