about summary refs log tree commit diff
path: root/src/libcoretest
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-27 22:46:48 +0000
committerbors <bors@rust-lang.org>2015-04-27 22:46:48 +0000
commit97d4e76c20ec2e80affd100dd169155914370fd2 (patch)
treedc2285a690b84ce31a19cfe61e401770a0b51d63 /src/libcoretest
parent9c88f3be126d0fe02a92c20e1d78192f4b648401 (diff)
parente129b92c40678f65490ce58fa06079d38ae07eba (diff)
downloadrust-97d4e76c20ec2e80affd100dd169155914370fd2.tar.gz
rust-97d4e76c20ec2e80affd100dd169155914370fd2.zip
Auto merge of #24701 - Stebalien:slice, r=alexcrichton
Instead of using the O(n) defaults, define O(1) shortcuts. I also copied (and slightly modified) the relevant tests from the iter tests into the slice tests just in case someone comes along and changes them in the future.

Partially implements  #24214.
Diffstat (limited to 'src/libcoretest')
-rw-r--r--src/libcoretest/slice.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libcoretest/slice.rs b/src/libcoretest/slice.rs
index fe73b3b4407..7c884a73ce0 100644
--- a/src/libcoretest/slice.rs
+++ b/src/libcoretest/slice.rs
@@ -82,3 +82,34 @@ fn iterator_to_slice() {
     test!([1u8,2,3]);
     test!([(),(),()]);
 }
+
+#[test]
+fn test_iterator_nth() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    for i in 0..v.len() {
+        assert_eq!(v.iter().nth(i).unwrap(), &v[i]);
+    }
+    assert_eq!(v.iter().nth(v.len()), None);
+
+    let mut iter = v.iter();
+    assert_eq!(iter.nth(2).unwrap(), &v[2]);
+    assert_eq!(iter.nth(1).unwrap(), &v[4]);
+}
+
+#[test]
+fn test_iterator_last() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    assert_eq!(v.iter().last().unwrap(), &4);
+    assert_eq!(v[..1].iter().last().unwrap(), &0);
+}
+
+#[test]
+fn test_iterator_count() {
+    let v: &[_] = &[0, 1, 2, 3, 4];
+    assert_eq!(v.iter().count(), 5);
+
+    let mut iter2 = v.iter();
+    iter2.next();
+    iter2.next();
+    assert_eq!(iter2.count(), 3);
+}