提交 919d643b 编写于 作者: V varkor

Add `min` and `last` specialisations for `Range`

上级 2d833435
......@@ -252,6 +252,16 @@ fn nth(&mut self, n: usize) -> Option<A> {
None
}
#[inline]
fn last(mut self) -> Option<A> {
self.next_back()
}
#[inline]
fn min(mut self) -> Option<A> {
self.next()
}
#[inline]
fn max(mut self) -> Option<A> {
self.next_back()
......
......@@ -1353,10 +1353,14 @@ fn test_range_step() {
}
#[test]
fn test_range_max() {
assert_eq!((0..100).max(), Some(99));
assert_eq!((-20..-10).max(), Some(-11));
assert_eq!((1..1).max(), None);
fn test_range_last_max() {
assert_eq!((0..20).last(), Some(19));
assert_eq!((-20..0).last(), Some(-1));
assert_eq!((5..5).last(), None);
assert_eq!((0..20).max(), Some(19));
assert_eq!((-20..0).max(), Some(-1));
assert_eq!((5..5).max(), None);
}
#[test]
......@@ -1376,6 +1380,13 @@ fn test_range_inclusive_last_max() {
assert_eq!(r.max(), None);
}
#[test]
fn test_range_min() {
assert_eq!((0..20).min(), Some(0));
assert_eq!((-20..0).min(), Some(-20));
assert_eq!((5..5).min(), None);
}
#[test]
fn test_range_inclusive_min() {
assert_eq!((0..=20).min(), Some(0));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册