Skip to main content

test_helpers/
lib.rs

1//! Test helpers for Rust.
2//!
3//! **test_help-rs** provides assertion macros and evaluators for
4//! approximate equality of floating-point scalars and vectors in unit
5//! tests — filling gaps around `f32` and `f64` comparisons in Rust's
6//! stock testing support.
7//!
8//! # Installation
9//!
10//! Reference in **Cargo.toml** in the usual way:
11//!
12//! ```toml
13//! test_help-rs = { version = "0.1" }
14//! ```
15//!
16//! # Components
17//!
18//! ## Macros
19//!
20//! * [`assert_scalar_eq_approx!`] — scalar approximate equality;
21//! * [`assert_scalar_ne_approx!`] — scalar approximate inequality;
22//! * [`assert_vector_eq_approx!`] — vector approximate equality;
23//! * [`assert_vector_ne_approx!`] — vector approximate inequality;
24//!
25//! ## Functions
26//!
27//! * [`margin`] — margin-based [`ApproximateEqualityEvaluator`];
28//! * [`multiplier`] — multiplier-based [`ApproximateEqualityEvaluator`];
29//! * [`zero_margin_or_multiplier`] — combined stock evaluator used by
30//!   the two-argument assertion macros;
31//! * [`evaluate_scalar_eq_approx`] — scalar comparison without
32//!   asserting;
33//! * [`evaluate_vector_eq_approx`] — vector comparison without
34//!   asserting;
35//!
36//! ## Types
37//!
38//! * [`ComparisonResult`] — outcome of a scalar comparison;
39//! * [`VectorComparisonResult`] — outcome of a vector comparison;
40//! * [`traits::ApproximateEqualityEvaluator`] — custom comparison
41//!   strategy;
42//! * [`traits::TestableAsF64`] — types usable with the assertion
43//!   macros (via [`base_traits::ToF64`]);
44//!
45//! ## Constants
46//!
47//! * [`constants::DEFAULT_MARGIN`] and [`constants::DEFAULT_MULTIPLIER`]
48//!   — stock tolerance values for the two-argument macros;
49//!
50//! # Examples
51//!
52//! ```
53//! use test_helpers::{assert_scalar_eq_approx, margin};
54//!
55//! assert_scalar_eq_approx!(3.0, 3.0001, margin(0.0001));
56//! ```
57//!
58//! See the project [README](https://github.com/synesissoftware/test_help-rs)
59//! for further information.
60
61// lib.rs : test_help-rs
62
63#![allow(non_camel_case_types)]
64#![cfg_attr(all(test, feature = "nightly-constants"), feature(more_float_constants))]
65
66macro_rules! declare_and_publish {
67    ($mod_name:ident, $($type_name:ident),* $(,)?) => {
68        mod $mod_name;
69
70        pub use $mod_name::{
71            $($type_name),*
72        };
73    };
74}
75
76declare_and_publish!(comparison_result, ComparisonResult);
77declare_and_publish!(vector_comparison_result, VectorComparisonResult);
78
79pub mod constants;
80pub mod traits;
81
82mod internal;
83#[macro_use]
84mod macros;
85mod utils;
86
87declare_and_publish!(
88    api,
89    evaluate_scalar_eq_approx,
90    evaluate_vector_eq_approx,
91    margin,
92    multiplier,
93    zero_margin_or_multiplier,
94);
95
96
97#[cfg(test)]
98#[rustfmt::skip]
99mod tests;
100
101// ///////////////////////////// end of file //////////////////////////// //