#testing #arrays #float

russell_chk

Functions to check vectors and other data in tests

8 unstable releases (3 breaking)

0.4.1 Jun 28, 2022
0.3.0 Jun 28, 2022
0.2.1 Oct 23, 2021
0.1.3 Oct 7, 2021
0.1.0 Jun 22, 2021

#331 in Math

Download history 35/week @ 2022-11-28 53/week @ 2022-12-05 82/week @ 2022-12-12 53/week @ 2022-12-19 42/week @ 2022-12-26 25/week @ 2023-01-02 42/week @ 2023-01-09 26/week @ 2023-01-16 66/week @ 2023-01-23 85/week @ 2023-01-30 41/week @ 2023-02-06 61/week @ 2023-02-13 79/week @ 2023-02-20 124/week @ 2023-02-27 72/week @ 2023-03-06 61/week @ 2023-03-13

360 downloads per month
Used in 9 crates (8 directly)

MIT license

33KB
554 lines

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

Crates.io

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::assert_approx_eq;

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::assert_vec_approx_eq;

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::assert_deriv_approx_eq;

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);
}

Check complex numbers

use russell_chk::assert_complex_vec_approx_eq;
use num_complex::Complex64;

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

Dependencies

~265KB