|
10 | 10 |
|
11 | 11 | #[allow(missing_doc)];
|
12 | 12 |
|
13 |
| -use std::cmp; |
14 | 13 | use std::hash::Hash;
|
15 | 14 | use std::io;
|
16 | 15 | use std::mem;
|
@@ -203,12 +202,12 @@ impl<'a> Stats for &'a [f64] {
|
203 | 202 |
|
204 | 203 | fn min(self) -> f64 {
|
205 | 204 | assert!(self.len() != 0);
|
206 |
| - self.iter().fold(self[0], |p,q| cmp::min(p, *q)) |
| 205 | + self.iter().fold(self[0], |p, q| p.min(*q)) |
207 | 206 | }
|
208 | 207 |
|
209 | 208 | fn max(self) -> f64 {
|
210 | 209 | assert!(self.len() != 0);
|
211 |
| - self.iter().fold(self[0], |p,q| cmp::max(p, *q)) |
| 210 | + self.iter().fold(self[0], |p, q| p.max(*q)) |
212 | 211 | }
|
213 | 212 |
|
214 | 213 | fn mean(self) -> f64 {
|
@@ -442,6 +441,7 @@ mod tests {
|
442 | 441 | use stats::write_boxplot;
|
443 | 442 | use std::io;
|
444 | 443 | use std::str;
|
| 444 | + use std::f64; |
445 | 445 |
|
446 | 446 | macro_rules! assert_approx_eq(
|
447 | 447 | ($a:expr, $b:expr) => ({
|
@@ -481,6 +481,14 @@ mod tests {
|
481 | 481 | assert_eq!(summ.iqr, summ2.iqr);
|
482 | 482 | }
|
483 | 483 |
|
| 484 | + #[test] |
| 485 | + fn test_min_max_nan() { |
| 486 | + let xs = &[1.0, 2.0, f64::NAN, 3.0, 4.0]; |
| 487 | + let summary = Summary::new(xs); |
| 488 | + assert_eq!(summary.min, 1.0); |
| 489 | + assert_eq!(summary.max, 4.0); |
| 490 | + } |
| 491 | + |
484 | 492 | #[test]
|
485 | 493 | fn test_norm2() {
|
486 | 494 | let val = &[
|
|
0 commit comments