From c75ffc01f198e2d7dbea8094a9668ed9e6a6a830 Mon Sep 17 00:00:00 2001 From: Vinzent Steinberg Date: Fri, 5 May 2017 15:59:50 +0200 Subject: [PATCH] Add example --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 42f5c68..20c2bb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -88,6 +88,19 @@ impl Average { } /// Merge the average of another sequence into this one. + /// + /// ``` + /// use average::Average; + /// + /// let sequence: &[f64] = &[1., 2., 3., 4., 5., 6., 7., 8., 9.]; + /// let (left, right) = sequence.split_at(3); + /// let avg_total: Average = sequence.iter().map(|x| *x).collect(); + /// let mut avg_left: Average = left.iter().map(|x| *x).collect(); + /// let avg_right: Average = right.iter().map(|x| *x).collect(); + /// avg_left.merge(&avg_right); + /// assert_eq!(avg_total.mean(), avg_left.mean()); + /// assert_eq!(avg_total.sample_variance(), avg_left.sample_variance()); + /// ``` pub fn merge(&mut self, other: &Average) { // This algorithm was proposed by Chan et al. in 1979. //