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
66pub(crate) mod macros;
67
68use crate::macros::declare_and_publish;
69
70declare_and_publish!(comparison_result, ComparisonResult);
71declare_and_publish!(vector_comparison_result, VectorComparisonResult);
72
73pub mod constants;
74pub mod traits;
75
76#[macro_use]
77mod assertions;
78#[macro_use]
79mod assertions_as_str;
80mod internal;
81mod utils;
82
83declare_and_publish!(
84 api,
85 evaluate_scalar_eq_approx,
86 evaluate_vector_eq_approx,
87 margin,
88 multiplier,
89 zero_margin_or_multiplier,
90);
91
92#[doc(hidden)]
93pub use base_traits;
94
95#[cfg(test)]
96#[rustfmt::skip]
97mod tests;
98
99
100// ///////////////////////////// end of file //////////////////////////// //