about summary refs log tree commit diff
path: root/src/libcore/tests
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-05-29 08:15:55 +0200
committerGitHub <noreply@github.com>2019-05-29 08:15:55 +0200
commitf0ea975a1c3be46d5ef6f84f7bc01fd89cc936af (patch)
tree60ce390f6d967ce0f8a0ccfaa7d3f4c93b9b7109 /src/libcore/tests
parentcb012a0430c4448ac1bb6be38b3186e80ba4bcb4 (diff)
parentbcfd1f39e7dcb824594d68b5d74732dc6d23cae9 (diff)
downloadrust-f0ea975a1c3be46d5ef6f84f7bc01fd89cc936af.tar.gz
rust-f0ea975a1c3be46d5ef6f84f7bc01fd89cc936af.zip
Rollup merge of #61048 - wizAmit:feature/nth_back_chunks, r=scottmcm
Feature/nth back chunks

A succinct implementation for nth_back on chunks. Thank you @timvermeulen for the guidance.

r? @timvermeulen
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 cd520a052a0..9710f019f4e 100644
--- a/src/libcore/tests/slice.rs
+++ b/src/libcore/tests/slice.rs
@@ -135,6 +135,30 @@ fn test_chunks_nth() {
 }
 
 #[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() {
     let v: &[i32] = &[0, 1, 2, 3, 4, 5];
     let c = v.chunks(2);