Clean up doctests
Also make sure that the macros work when they are imported in isolation.
This commit is contained in:
parent
c9829a1279
commit
610f6cae6a
@ -10,12 +10,7 @@
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate core;
|
||||
/// # #[macro_use] extern crate average;
|
||||
/// # #[cfg(feature = "serde1")] #[macro_use] extern crate serde_derive;
|
||||
/// # #[cfg(feature = "serde1")] #[macro_use] extern crate serde_big_array;
|
||||
/// # fn main() {
|
||||
/// use average::Histogram;
|
||||
/// use average::{Histogram, define_histogram};
|
||||
///
|
||||
/// define_histogram!(hist, 10);
|
||||
/// let mut h = hist::Histogram::with_const_width(0., 100.);
|
||||
@ -23,14 +18,13 @@
|
||||
/// h.add(i as f64).unwrap();
|
||||
/// }
|
||||
/// assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! define_histogram {
|
||||
($name:ident, $LEN:expr) => (
|
||||
mod $name {
|
||||
use $crate::Histogram as Trait;
|
||||
#[cfg(feature = "serde1")] big_array! {
|
||||
#[cfg(feature = "serde1")] serde_big_array::big_array! {
|
||||
BigArray; LEN, (LEN + 1),
|
||||
}
|
||||
|
||||
|
10
src/lib.rs
10
src/lib.rs
@ -90,16 +90,6 @@
|
||||
|
||||
#![no_std]
|
||||
|
||||
|
||||
|
||||
#[cfg(feature = "serde1")]
|
||||
extern crate serde;
|
||||
#[cfg(feature = "serde1")]
|
||||
#[macro_use] extern crate serde_derive;
|
||||
#[cfg(feature = "serde1")]
|
||||
#[macro_use] extern crate serde_big_array;
|
||||
|
||||
|
||||
#[macro_use] mod macros;
|
||||
#[macro_use] mod moments;
|
||||
mod weighted_mean;
|
||||
|
@ -37,10 +37,7 @@ macro_rules! assert_almost_eq {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate core;
|
||||
/// # #[macro_use] extern crate average;
|
||||
/// # fn main() {
|
||||
/// use average::{Min, Max, Estimate};
|
||||
/// use average::{Min, Max, Estimate, concatenate};
|
||||
///
|
||||
/// concatenate!(MinMax, [Min, min], [Max, max]);
|
||||
///
|
||||
@ -48,7 +45,6 @@ macro_rules! assert_almost_eq {
|
||||
///
|
||||
/// assert_eq!(s.min(), 1.0);
|
||||
/// assert_eq!(s.max(), 5.0);
|
||||
/// # }
|
||||
/// ```
|
||||
///
|
||||
/// The generated code looks roughly like this:
|
||||
@ -85,15 +81,11 @@ macro_rules! assert_almost_eq {
|
||||
/// can do the following:
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate core;
|
||||
/// # #[macro_use] extern crate average;
|
||||
/// # fn main() {
|
||||
/// use average::{Variance, Quantile, Estimate};
|
||||
/// use average::{Variance, Quantile, Estimate, concatenate};
|
||||
///
|
||||
/// concatenate!(Estimator,
|
||||
/// [Variance, variance, mean, sample_variance],
|
||||
/// [Quantile, quantile, quantile]);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! concatenate {
|
||||
|
@ -31,15 +31,8 @@ pub type MeanWithError = Variance;
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// # extern crate core;
|
||||
/// # extern crate conv;
|
||||
/// # extern crate num_traits;
|
||||
/// #[cfg(feature = "serde1")]
|
||||
/// extern crate serde;
|
||||
/// #[cfg(feature = "serde1")]
|
||||
/// #[macro_use] extern crate serde_derive;
|
||||
/// # #[macro_use] extern crate average;
|
||||
/// # fn main() {
|
||||
/// use average::{define_moments, assert_almost_eq};
|
||||
///
|
||||
/// define_moments!(Moments4, 4);
|
||||
///
|
||||
/// let mut a: Moments4 = (1..6).map(f64::from).collect();
|
||||
@ -56,7 +49,6 @@ pub type MeanWithError = Variance;
|
||||
/// assert_almost_eq!(a.standardized_moment(3), 0.2795084971874741, 1e-15);
|
||||
/// // kurtosis
|
||||
/// assert_almost_eq!(a.standardized_moment(4), -1.365 + 3.0, 1e-14);
|
||||
/// # }
|
||||
/// ```
|
||||
#[macro_export]
|
||||
macro_rules! define_moments {
|
||||
@ -301,6 +293,6 @@ macro_rules! define_moments {
|
||||
}
|
||||
}
|
||||
|
||||
impl_from_iterator!($name);
|
||||
$crate::impl_from_iterator!($name);
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
#[cfg(feature = "serde1")]
|
||||
#[macro_use] extern crate serde_big_array;
|
||||
|
||||
use core::iter::Iterator;
|
||||
use rand::SeedableRng;
|
||||
use rand_distr::Distribution;
|
||||
|
Loading…
Reference in New Issue
Block a user