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 stock
6//! testing support.
7//!
8//! Scalar comparisons report exact, approximate, or unequal results. Vector
9//! comparisons apply the same evaluator element-wise and also report
10//! unequal lengths or the first unequal element.
11//!
12//! The stock tolerance helpers are [`margin`], [`multiplier`], and
13//! [`zero_margin_or_multiplier`]. Custom
14//! [`traits::ApproximateEqualityEvaluator`] implementations can provide
15//! other comparison strategies.
16//!
17//! The optional `"nan-equality"` feature treats two `NaN` values as exactly
18//! equal in stock comparisons. The `"nightly-constants"` feature enables
19//! additional standard-library constant tests and requires a nightly
20//! toolchain; it is intended for crate development rather than downstream
21//! use.
22//!
23//! # Installation
24//!
25//! Reference in **Cargo.toml** in the usual way:
26//!
27//! ```toml
28//! test_help-rs = { version = "0.2.1" }
29//! ```
30//!
31//! # Components
32//!
33//! ## Macros
34//!
35//! * [`assert_scalar_eq_approx!`] — scalar approximate equality;
36//! * [`assert_scalar_ne_approx!`] — scalar approximate inequality;
37//! * [`assert_vector_eq_approx!`] — vector approximate equality;
38//! * [`assert_vector_ne_approx!`] — vector approximate inequality;
39//!
40//! ## Functions
41//!
42//! * [`margin`] — margin-based
43//! [`traits::ApproximateEqualityEvaluator`];
44//! * [`multiplier`] — multiplier-based
45//! [`traits::ApproximateEqualityEvaluator`];
46//! * [`zero_margin_or_multiplier`] — combined stock evaluator used by the
47//! two-argument assertion macros;
48//! * [`evaluate_scalar_eq_approx`] — scalar comparison without asserting;
49//! * [`evaluate_vector_eq_approx`] — vector comparison without asserting;
50//!
51//! ## Types
52//!
53//! * [`ComparisonResult`] — outcome of a scalar comparison;
54//! * [`VectorComparisonResult`] — outcome of a vector comparison;
55//! * [`traits::ApproximateEqualityEvaluator`] — custom comparison strategy;
56//! * [`traits::TestableAsF64`] — types usable with the assertion macros
57//! (via [`base_traits::ToF64`]);
58//!
59//! ## Constants
60//!
61//! * [`constants::DEFAULT_MARGIN`] and [`constants::DEFAULT_MULTIPLIER`]
62//! — stock tolerance values for the two-argument macros;
63//!
64//! # Examples
65//!
66//! ```
67//! use test_helpers::{assert_scalar_eq_approx, margin};
68//!
69//! assert_scalar_eq_approx!(3.0, 3.0001, margin(0.0001));
70//! ```
71//!
72//! See the project [README](https://github.com/synesissoftware/test_help-rs)
73//! for further information.
74
75// lib.rs : test_help-rs
76
77#![allow(non_camel_case_types)]
78#![cfg_attr(all(test, feature = "nightly-constants"), feature(more_float_constants))]
79
80pub(crate) mod macros;
81
82use crate::macros::declare_and_publish;
83
84declare_and_publish!(comparison_result, ComparisonResult);
85declare_and_publish!(vector_comparison_result, VectorComparisonResult);
86
87pub mod constants;
88pub mod traits;
89
90#[macro_use]
91mod assertions;
92#[macro_use]
93mod assertions_as_str;
94mod internal;
95mod utils;
96
97declare_and_publish!(
98 api,
99 evaluate_scalar_eq_approx,
100 evaluate_vector_eq_approx,
101 margin,
102 multiplier,
103 zero_margin_or_multiplier,
104);
105
106#[doc(hidden)]
107pub use base_traits;
108
109#[cfg(test)]
110#[rustfmt::skip]
111mod tests;
112
113
114// ///////////////////////////// end of file //////////////////////////// //