From cb020db55a009a65599f31da6a0316c0aaae19a2 Mon Sep 17 00:00:00 2001 From: Ahmed Charles Date: Wed, 21 Jan 2015 04:39:27 -0800 Subject: [PATCH] Remove remaining stats and boxplot code. --- src/libtest/lib.rs | 33 +---------- src/libtest/stats.rs | 130 ------------------------------------------- 2 files changed, 2 insertions(+), 161 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3412e61ff153f..7226c6423b82c 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -437,9 +437,6 @@ struct ConsoleTestState { log_out: Option, out: OutputLocation, use_color: bool, - show_boxplot: bool, - boxplot_width: uint, - show_all_stats: bool, total: uint, passed: uint, failed: uint, @@ -466,9 +463,6 @@ impl ConsoleTestState { out: out, log_out: log_out, use_color: use_color(opts), - show_boxplot: false, - boxplot_width: 50, - show_all_stats: false, total: 0u, passed: 0u, failed: 0u, @@ -549,28 +543,8 @@ impl ConsoleTestState { TrBench(ref bs) => { try!(self.write_bench()); - if self.show_boxplot { - let mut wr = Vec::new(); - - try!(stats::write_boxplot(&mut wr, &bs.ns_iter_summ, self.boxplot_width)); - - let s = String::from_utf8(wr).unwrap(); - - try!(self.write_plain(format!(": {}", s).as_slice())); - } - - if self.show_all_stats { - let mut wr = Vec::new(); - - try!(stats::write_5_number_summary(&mut wr, &bs.ns_iter_summ)); - - let s = String::from_utf8(wr).unwrap(); - - try!(self.write_plain(format!(": {}", s).as_slice())); - } else { - try!(self.write_plain(format!(": {}", - fmt_bench_samples(bs)).as_slice())); - } + try!(self.write_plain(format!(": {}", + fmt_bench_samples(bs)).as_slice())); Ok(()) } @@ -736,9 +710,6 @@ fn should_sort_failures_before_printing_them() { log_out: None, out: Raw(Vec::new()), use_color: false, - show_boxplot: false, - boxplot_width: 0, - show_all_stats: false, total: 0u, passed: 0u, failed: 0u, diff --git a/src/libtest/stats.rs b/src/libtest/stats.rs index cd461cf5766d6..76b85cc10cd89 100644 --- a/src/libtest/stats.rs +++ b/src/libtest/stats.rs @@ -13,9 +13,7 @@ use std::cmp::Ordering::{self, Less, Greater, Equal}; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::hash_map::{self, Hasher}; -use std::fmt; use std::hash::Hash; -use std::io; use std::mem; use std::num::{Float, FromPrimitive}; @@ -332,111 +330,6 @@ pub fn winsorize(samples: &mut [T], pct: T) { } } -/// Render writes the min, max and quartiles of the provided `Summary` to the provided `Writer`. -pub fn write_5_number_summary(w: &mut W, - s: &Summary) -> io::IoResult<()> { - let (q1,q2,q3) = s.quartiles; - write!(w, "(min={}, q1={}, med={}, q3={}, max={})", - s.min, - q1, - q2, - q3, - s.max) -} - -/// Render a boxplot to the provided writer. The boxplot shows the min, max and quartiles of the -/// provided `Summary` (thus includes the mean) and is scaled to display within the range of the -/// nearest multiple-of-a-power-of-ten above and below the min and max of possible values, and -/// target `width_hint` characters of display (though it will be wider if necessary). -/// -/// As an example, the summary with 5-number-summary `(min=15, q1=17, med=20, q3=24, max=31)` might -/// display as: -/// -/// ```{.ignore} -/// 10 | [--****#******----------] | 40 -/// ``` -pub fn write_boxplot( - w: &mut W, - s: &Summary, - width_hint: uint) - -> io::IoResult<()> { - - let (q1,q2,q3) = s.quartiles; - - // the .abs() handles the case where numbers are negative - let ten: T = FromPrimitive::from_uint(10).unwrap(); - let lomag = ten.powf(s.min.abs().log10().floor()); - let himag = ten.powf(s.max.abs().log10().floor()); - - // need to consider when the limit is zero - let zero: T = Float::zero(); - let lo = if lomag == Float::zero() { - zero - } else { - (s.min / lomag).floor() * lomag - }; - - let hi = if himag == Float::zero() { - zero - } else { - (s.max / himag).ceil() * himag - }; - - let range = hi - lo; - - let lostr = lo.to_string(); - let histr = hi.to_string(); - - let overhead_width = lostr.len() + histr.len() + 4; - let range_width = width_hint - overhead_width; - let range_float = FromPrimitive::from_uint(range_width).unwrap(); - let char_step = range / range_float; - - try!(write!(w, "{} |", lostr)); - - let mut c = 0; - let mut v = lo; - - while c < range_width && v < s.min { - try!(write!(w, " ")); - v = v + char_step; - c += 1; - } - try!(write!(w, "[")); - c += 1; - while c < range_width && v < q1 { - try!(write!(w, "-")); - v = v + char_step; - c += 1; - } - while c < range_width && v < q2 { - try!(write!(w, "*")); - v = v + char_step; - c += 1; - } - try!(write!(w, "#")); - c += 1; - while c < range_width && v < q3 { - try!(write!(w, "*")); - v = v + char_step; - c += 1; - } - while c < range_width && v < s.max { - try!(write!(w, "-")); - v = v + char_step; - c += 1; - } - try!(write!(w, "]")); - while c < range_width { - try!(write!(w, " ")); - v = v + char_step; - c += 1; - } - - try!(write!(w, "| {}", histr)); - Ok(()) -} - /// Returns a HashMap with the number of occurrences of every element in the /// sequence that the iterator exposes. pub fn freq_count(mut iter: T) -> hash_map::HashMap @@ -458,8 +351,6 @@ pub fn freq_count(mut iter: T) -> hash_map::HashMap mod tests { use stats::Stats; use stats::Summary; - use stats::write_5_number_summary; - use stats::write_boxplot; use std::io; use std::f64; @@ -479,10 +370,6 @@ mod tests { let mut w = io::stdout(); let w = &mut w; (write!(w, "\n")).unwrap(); - write_5_number_summary(w, &summ2).unwrap(); - (write!(w, "\n")).unwrap(); - write_boxplot(w, &summ2, 50).unwrap(); - (write!(w, "\n")).unwrap(); assert_eq!(summ.sum, summ2.sum); assert_eq!(summ.min, summ2.min); @@ -1028,23 +915,6 @@ mod tests { check(val, summ); } - #[test] - fn test_boxplot_nonpositive() { - fn t(s: &Summary, expected: String) { - let mut m = Vec::new(); - write_boxplot(&mut m, s, 30).unwrap(); - let out = String::from_utf8(m).unwrap(); - assert_eq!(out, expected); - } - - t(&Summary::new(&[-2.0f64, -1.0f64]), - "-2 |[------******#*****---]| -1".to_string()); - t(&Summary::new(&[0.0f64, 2.0f64]), - "0 |[-------*****#*******---]| 2".to_string()); - t(&Summary::new(&[-2.0f64, 0.0f64]), - "-2 |[------******#******---]| 0".to_string()); - - } #[test] fn test_sum_f64s() { assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999);