about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorwizAmit <amitforfriends_dns@yahoo.com>2019-05-22 22:27:30 +0530
committerwizAmit <amitforfriends_dns@yahoo.com>2019-05-22 22:27:30 +0530
commit9309447397ffcc2f427f850c1a7df8af2c682169 (patch)
treead905f2aa3189f34cc734a8f2e0b68c153fd0aae /src/libcore/tests
parent29a103daa92bb3607fd4cd34169d4ff6170987fa (diff)
downloadrust-9309447397ffcc2f427f850c1a7df8af2c682169.tar.gz
rust-9309447397ffcc2f427f850c1a7df8af2c682169.zip
succint implementation
Diffstat (limited to 'src/libcore/tests')
-rw-r--r--src/libcore/tests/slice.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libcore/tests/slice.rs b/src/libcore/tests/slice.rs
index 1cba4b38382..a4cb0c42044 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -134,6 +134,30 @@ fn test_chunks_nth() {
     assert_eq!(c2.next(), None);
 }
 
+#[test]
+fn test_chunks_nth_back() {
+    let v: &[i32] = &[0, 1, 2, 3, 4, 5];
+    let mut c = v.chunks(2);
+    assert_eq!(c.nth_back(1).unwrap(), &[2, 3]);
+    assert_eq!(c.next().unwrap(), &[0, 1]);
+    assert_eq!(c.next(), None);
+
+    let v2: &[i32] = &[0, 1, 2, 3, 4];
+    let mut c2 = v2.chunks(3);
+    assert_eq!(c2.nth_back(1).unwrap(), &[0, 1, 2]);
+    assert_eq!(c2.next(), None);
+    assert_eq!(c2.next_back(), None);
+
+    let v3: &[i32] = &[0, 1, 2, 3, 4];
+    let mut c3 = v3.chunks(10);
+    assert_eq!(c3.nth_back(0).unwrap(), &[0, 1, 2, 3, 4]);
+    assert_eq!(c3.next(), None);
+
+    let v4: &[i32] = &[0, 1, 2];
+    let mut c4 = v4.chunks(10);
+    assert_eq!(c4.nth_back(1_000_000_000usize), None);
+}
+
 
 #[test]
 fn test_chunks_last() {