diff options
| author | philipp <philipp> | 2016-08-20 15:12:50 +0200 |
|---|---|---|
| committer | philipp <philipp> | 2016-08-20 17:30:48 +0200 |
| commit | 4b87c7e3b419345e2d0fd35987a2e012b1e95a5e (patch) | |
| tree | e888a69791409abe6782468f860afbe25f897d16 /src/libcoretest | |
| parent | 7ac11cad3fe85163dd8b0ca1f63af492509f9bfe (diff) | |
| download | rust-4b87c7e3b419345e2d0fd35987a2e012b1e95a5e.tar.gz rust-4b87c7e3b419345e2d0fd35987a2e012b1e95a5e.zip | |
Introduce max_by/min_by on iterators
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/iter.rs | 12 | ||||
| -rw-r--r-- | src/libcoretest/lib.rs | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/libcoretest/iter.rs b/src/libcoretest/iter.rs index a2848faa105..27eb25537f3 100644 --- a/src/libcoretest/iter.rs +++ b/src/libcoretest/iter.rs @@ -665,12 +665,24 @@ fn test_max_by_key() { } #[test] +fn test_max_by() { + let xs: &[isize] = &[-3, 0, 1, 5, -10]; + assert_eq!(*xs.iter().max_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), -10); +} + +#[test] fn test_min_by_key() { let xs: &[isize] = &[-3, 0, 1, 5, -10]; assert_eq!(*xs.iter().min_by_key(|x| x.abs()).unwrap(), 0); } #[test] +fn test_min_by() { + let xs: &[isize] = &[-3, 0, 1, 5, -10]; + assert_eq!(*xs.iter().min_by(|x, y| x.abs().cmp(&y.abs())).unwrap(), 0); +} + +#[test] fn test_by_ref() { let mut xs = 0..10; // sum the first five values diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 9428b4096bf..b4c94509477 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -33,6 +33,8 @@ #![feature(try_from)] #![feature(unicode)] #![feature(unique)] +#![feature(iter_max_by)] +#![feature(iter_min_by)] extern crate core; extern crate test; |
