Skip to content

Commit cb020db

Browse files
committed
Remove remaining stats and boxplot code.
1 parent 989fbfd commit cb020db

File tree

2 files changed

+2
-161
lines changed

2 files changed

+2
-161
lines changed

src/libtest/lib.rs

+2-31
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,6 @@ struct ConsoleTestState<T> {
437437
log_out: Option<File>,
438438
out: OutputLocation<T>,
439439
use_color: bool,
440-
show_boxplot: bool,
441-
boxplot_width: uint,
442-
show_all_stats: bool,
443440
total: uint,
444441
passed: uint,
445442
failed: uint,
@@ -466,9 +463,6 @@ impl<T: Writer> ConsoleTestState<T> {
466463
out: out,
467464
log_out: log_out,
468465
use_color: use_color(opts),
469-
show_boxplot: false,
470-
boxplot_width: 50,
471-
show_all_stats: false,
472466
total: 0u,
473467
passed: 0u,
474468
failed: 0u,
@@ -549,28 +543,8 @@ impl<T: Writer> ConsoleTestState<T> {
549543
TrBench(ref bs) => {
550544
try!(self.write_bench());
551545

552-
if self.show_boxplot {
553-
let mut wr = Vec::new();
554-
555-
try!(stats::write_boxplot(&mut wr, &bs.ns_iter_summ, self.boxplot_width));
556-
557-
let s = String::from_utf8(wr).unwrap();
558-
559-
try!(self.write_plain(format!(": {}", s).as_slice()));
560-
}
561-
562-
if self.show_all_stats {
563-
let mut wr = Vec::new();
564-
565-
try!(stats::write_5_number_summary(&mut wr, &bs.ns_iter_summ));
566-
567-
let s = String::from_utf8(wr).unwrap();
568-
569-
try!(self.write_plain(format!(": {}", s).as_slice()));
570-
} else {
571-
try!(self.write_plain(format!(": {}",
572-
fmt_bench_samples(bs)).as_slice()));
573-
}
546+
try!(self.write_plain(format!(": {}",
547+
fmt_bench_samples(bs)).as_slice()));
574548

575549
Ok(())
576550
}
@@ -736,9 +710,6 @@ fn should_sort_failures_before_printing_them() {
736710
log_out: None,
737711
out: Raw(Vec::new()),
738712
use_color: false,
739-
show_boxplot: false,
740-
boxplot_width: 0,
741-
show_all_stats: false,
742713
total: 0u,
743714
passed: 0u,
744715
failed: 0u,

src/libtest/stats.rs

-130
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
use std::cmp::Ordering::{self, Less, Greater, Equal};
1414
use std::collections::hash_map::Entry::{Occupied, Vacant};
1515
use std::collections::hash_map::{self, Hasher};
16-
use std::fmt;
1716
use std::hash::Hash;
18-
use std::io;
1917
use std::mem;
2018
use std::num::{Float, FromPrimitive};
2119

@@ -332,111 +330,6 @@ pub fn winsorize<T: Float + FromPrimitive>(samples: &mut [T], pct: T) {
332330
}
333331
}
334332

335-
/// Render writes the min, max and quartiles of the provided `Summary` to the provided `Writer`.
336-
pub fn write_5_number_summary<W: Writer, T: Float + fmt::Display + fmt::Debug>(w: &mut W,
337-
s: &Summary<T>) -> io::IoResult<()> {
338-
let (q1,q2,q3) = s.quartiles;
339-
write!(w, "(min={}, q1={}, med={}, q3={}, max={})",
340-
s.min,
341-
q1,
342-
q2,
343-
q3,
344-
s.max)
345-
}
346-
347-
/// Render a boxplot to the provided writer. The boxplot shows the min, max and quartiles of the
348-
/// provided `Summary` (thus includes the mean) and is scaled to display within the range of the
349-
/// nearest multiple-of-a-power-of-ten above and below the min and max of possible values, and
350-
/// target `width_hint` characters of display (though it will be wider if necessary).
351-
///
352-
/// As an example, the summary with 5-number-summary `(min=15, q1=17, med=20, q3=24, max=31)` might
353-
/// display as:
354-
///
355-
/// ```{.ignore}
356-
/// 10 | [--****#******----------] | 40
357-
/// ```
358-
pub fn write_boxplot<W: Writer, T: Float + fmt::Display + fmt::Debug + FromPrimitive>(
359-
w: &mut W,
360-
s: &Summary<T>,
361-
width_hint: uint)
362-
-> io::IoResult<()> {
363-
364-
let (q1,q2,q3) = s.quartiles;
365-
366-
// the .abs() handles the case where numbers are negative
367-
let ten: T = FromPrimitive::from_uint(10).unwrap();
368-
let lomag = ten.powf(s.min.abs().log10().floor());
369-
let himag = ten.powf(s.max.abs().log10().floor());
370-
371-
// need to consider when the limit is zero
372-
let zero: T = Float::zero();
373-
let lo = if lomag == Float::zero() {
374-
zero
375-
} else {
376-
(s.min / lomag).floor() * lomag
377-
};
378-
379-
let hi = if himag == Float::zero() {
380-
zero
381-
} else {
382-
(s.max / himag).ceil() * himag
383-
};
384-
385-
let range = hi - lo;
386-
387-
let lostr = lo.to_string();
388-
let histr = hi.to_string();
389-
390-
let overhead_width = lostr.len() + histr.len() + 4;
391-
let range_width = width_hint - overhead_width;
392-
let range_float = FromPrimitive::from_uint(range_width).unwrap();
393-
let char_step = range / range_float;
394-
395-
try!(write!(w, "{} |", lostr));
396-
397-
let mut c = 0;
398-
let mut v = lo;
399-
400-
while c < range_width && v < s.min {
401-
try!(write!(w, " "));
402-
v = v + char_step;
403-
c += 1;
404-
}
405-
try!(write!(w, "["));
406-
c += 1;
407-
while c < range_width && v < q1 {
408-
try!(write!(w, "-"));
409-
v = v + char_step;
410-
c += 1;
411-
}
412-
while c < range_width && v < q2 {
413-
try!(write!(w, "*"));
414-
v = v + char_step;
415-
c += 1;
416-
}
417-
try!(write!(w, "#"));
418-
c += 1;
419-
while c < range_width && v < q3 {
420-
try!(write!(w, "*"));
421-
v = v + char_step;
422-
c += 1;
423-
}
424-
while c < range_width && v < s.max {
425-
try!(write!(w, "-"));
426-
v = v + char_step;
427-
c += 1;
428-
}
429-
try!(write!(w, "]"));
430-
while c < range_width {
431-
try!(write!(w, " "));
432-
v = v + char_step;
433-
c += 1;
434-
}
435-
436-
try!(write!(w, "| {}", histr));
437-
Ok(())
438-
}
439-
440333
/// Returns a HashMap with the number of occurrences of every element in the
441334
/// sequence that the iterator exposes.
442335
pub fn freq_count<T, U>(mut iter: T) -> hash_map::HashMap<U, uint>
@@ -458,8 +351,6 @@ pub fn freq_count<T, U>(mut iter: T) -> hash_map::HashMap<U, uint>
458351
mod tests {
459352
use stats::Stats;
460353
use stats::Summary;
461-
use stats::write_5_number_summary;
462-
use stats::write_boxplot;
463354
use std::io;
464355
use std::f64;
465356

@@ -479,10 +370,6 @@ mod tests {
479370
let mut w = io::stdout();
480371
let w = &mut w;
481372
(write!(w, "\n")).unwrap();
482-
write_5_number_summary(w, &summ2).unwrap();
483-
(write!(w, "\n")).unwrap();
484-
write_boxplot(w, &summ2, 50).unwrap();
485-
(write!(w, "\n")).unwrap();
486373

487374
assert_eq!(summ.sum, summ2.sum);
488375
assert_eq!(summ.min, summ2.min);
@@ -1028,23 +915,6 @@ mod tests {
1028915
check(val, summ);
1029916
}
1030917

1031-
#[test]
1032-
fn test_boxplot_nonpositive() {
1033-
fn t(s: &Summary<f64>, expected: String) {
1034-
let mut m = Vec::new();
1035-
write_boxplot(&mut m, s, 30).unwrap();
1036-
let out = String::from_utf8(m).unwrap();
1037-
assert_eq!(out, expected);
1038-
}
1039-
1040-
t(&Summary::new(&[-2.0f64, -1.0f64]),
1041-
"-2 |[------******#*****---]| -1".to_string());
1042-
t(&Summary::new(&[0.0f64, 2.0f64]),
1043-
"0 |[-------*****#*******---]| 2".to_string());
1044-
t(&Summary::new(&[-2.0f64, 0.0f64]),
1045-
"-2 |[------******#******---]| 0".to_string());
1046-
1047-
}
1048918
#[test]
1049919
fn test_sum_f64s() {
1050920
assert_eq!([0.5f64, 3.2321f64, 1.5678f64].sum(), 5.2999);

0 commit comments

Comments
 (0)