about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2018-03-01 01:57:25 -0800
committerScott McMurray <scottmcm@users.noreply.github.com>2018-03-01 01:57:25 -0800
commit70d5a4600b21451aa98b447cd59384d86e2eadce (patch)
tree5d1a396c78855cb8a510c3e69282f129c19cb4bf /src/libcore/tests
parenta85417f5938023d1491b44d94da705f539bb8b17 (diff)
Specialize Zip::nth for TrustedRandomAccess
Makes the bench asked about on URLO 58x faster :)
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/iter.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/tests/iter.rs b/src/libcore/tests/iter.rs
index edd75f7795e..5e2fef95d26 100644
--- a/src/libcore/tests/iter.rs
+++ b/src/libcore/tests/iter.rs
@@ -145,6 +145,23 @@ fn test_iterator_chain_find() {
 }
 
 #[test]
+fn test_zip_nth() {
+    let xs = [0, 1, 2, 4, 5];
+    let ys = [10, 11, 12];
+
+    let mut it = xs.iter().zip(&ys);
+    assert_eq!(it.nth(0), Some((&0, &10)));
+    assert_eq!(it.nth(1), Some((&2, &12)));
+    assert_eq!(it.nth(0), None);
+
+    let mut it = xs.iter().zip(&ys);
+    assert_eq!(it.nth(3), None);
+
+    let mut it = ys.iter().zip(&xs);
+    assert_eq!(it.nth(3), None);
+}
+
+#[test]
 fn test_iterator_step_by() {
     // Identity
     let mut it = (0..).step_by(1).take(3);