Clean up doctests

Also make sure that the macros work when they are imported in isolation.
This commit is contained in:
Vinzent Steinberg 2019-07-08 16:57:53 +02:00
parent c9829a1279
commit 610f6cae6a
5 changed files with 7 additions and 42 deletions

View File

@ -10,12 +10,7 @@
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate core; /// use average::{Histogram, define_histogram};
/// # #[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;
/// ///
/// define_histogram!(hist, 10); /// define_histogram!(hist, 10);
/// let mut h = hist::Histogram::with_const_width(0., 100.); /// let mut h = hist::Histogram::with_const_width(0., 100.);
@ -23,14 +18,13 @@
/// h.add(i as f64).unwrap(); /// h.add(i as f64).unwrap();
/// } /// }
/// assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]); /// assert_eq!(h.bins(), &[10, 10, 10, 10, 10, 10, 10, 10, 10, 10]);
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! define_histogram { macro_rules! define_histogram {
($name:ident, $LEN:expr) => ( ($name:ident, $LEN:expr) => (
mod $name { mod $name {
use $crate::Histogram as Trait; use $crate::Histogram as Trait;
#[cfg(feature = "serde1")] big_array! { #[cfg(feature = "serde1")] serde_big_array::big_array! {
BigArray; LEN, (LEN + 1), BigArray; LEN, (LEN + 1),
} }

View File

@ -90,16 +90,6 @@
#![no_std] #![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 macros;
#[macro_use] mod moments; #[macro_use] mod moments;
mod weighted_mean; mod weighted_mean;

View File

@ -37,10 +37,7 @@ macro_rules! assert_almost_eq {
/// # Examples /// # Examples
/// ///
/// ``` /// ```
/// # extern crate core; /// use average::{Min, Max, Estimate, concatenate};
/// # #[macro_use] extern crate average;
/// # fn main() {
/// use average::{Min, Max, Estimate};
/// ///
/// concatenate!(MinMax, [Min, min], [Max, max]); /// concatenate!(MinMax, [Min, min], [Max, max]);
/// ///
@ -48,7 +45,6 @@ macro_rules! assert_almost_eq {
/// ///
/// assert_eq!(s.min(), 1.0); /// assert_eq!(s.min(), 1.0);
/// assert_eq!(s.max(), 5.0); /// assert_eq!(s.max(), 5.0);
/// # }
/// ``` /// ```
/// ///
/// The generated code looks roughly like this: /// The generated code looks roughly like this:
@ -85,15 +81,11 @@ macro_rules! assert_almost_eq {
/// can do the following: /// can do the following:
/// ///
/// ``` /// ```
/// # extern crate core; /// use average::{Variance, Quantile, Estimate, concatenate};
/// # #[macro_use] extern crate average;
/// # fn main() {
/// use average::{Variance, Quantile, Estimate};
/// ///
/// concatenate!(Estimator, /// concatenate!(Estimator,
/// [Variance, variance, mean, sample_variance], /// [Variance, variance, mean, sample_variance],
/// [Quantile, quantile, quantile]); /// [Quantile, quantile, quantile]);
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! concatenate { macro_rules! concatenate {

View File

@ -31,15 +31,8 @@ pub type MeanWithError = Variance;
/// # Example /// # Example
/// ///
/// ``` /// ```
/// # extern crate core; /// use average::{define_moments, assert_almost_eq};
/// # 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() {
/// define_moments!(Moments4, 4); /// define_moments!(Moments4, 4);
/// ///
/// let mut a: Moments4 = (1..6).map(f64::from).collect(); /// 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); /// assert_almost_eq!(a.standardized_moment(3), 0.2795084971874741, 1e-15);
/// // kurtosis /// // kurtosis
/// assert_almost_eq!(a.standardized_moment(4), -1.365 + 3.0, 1e-14); /// assert_almost_eq!(a.standardized_moment(4), -1.365 + 3.0, 1e-14);
/// # }
/// ``` /// ```
#[macro_export] #[macro_export]
macro_rules! define_moments { macro_rules! define_moments {
@ -301,6 +293,6 @@ macro_rules! define_moments {
} }
} }
impl_from_iterator!($name); $crate::impl_from_iterator!($name);
); );
} }

View File

@ -1,6 +1,3 @@
#[cfg(feature = "serde1")]
#[macro_use] extern crate serde_big_array;
use core::iter::Iterator; use core::iter::Iterator;
use rand::SeedableRng; use rand::SeedableRng;
use rand_distr::Distribution; use rand_distr::Distribution;