Skip to content

Commit

Permalink
Test the whole chunks instead of just an element in the chunks/chunks…
Browse files Browse the repository at this point in the history
…_mut tests

Easy enough to do and ensures that the whole chunk is as expected
instead of just the element that was looked at before.
  • Loading branch information
sdroege committed Jan 13, 2018
1 parent baa81dc commit ed77483
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/libcore/tests/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ fn test_chunks_count() {
fn test_chunks_nth() {
let v: &[i32] = &[0, 1, 2, 3, 4, 5];
let mut c = v.chunks(2);
assert_eq!(c.nth(1).unwrap()[1], 3);
assert_eq!(c.next().unwrap()[0], 4);
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
assert_eq!(c.next().unwrap(), &[4, 5]);

let v2: &[i32] = &[0, 1, 2, 3, 4];
let mut c2 = v2.chunks(3);
assert_eq!(c2.nth(1).unwrap()[1], 4);
assert_eq!(c2.nth(1).unwrap(), &[3, 4]);
assert_eq!(c2.next(), None);
}

Expand Down Expand Up @@ -168,24 +168,24 @@ fn test_chunks_mut_count() {
fn test_chunks_mut_nth() {
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
let mut c = v.chunks_mut(2);
assert_eq!(c.nth(1).unwrap()[1], 3);
assert_eq!(c.next().unwrap()[0], 4);
assert_eq!(c.nth(1).unwrap(), &[2, 3]);
assert_eq!(c.next().unwrap(), &[4, 5]);

let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
let mut c2 = v2.chunks_mut(3);
assert_eq!(c2.nth(1).unwrap()[1], 4);
assert_eq!(c2.nth(1).unwrap(), &[3, 4]);
assert_eq!(c2.next(), None);
}

#[test]
fn test_chunks_mut_last() {
let v: &mut [i32] = &mut [0, 1, 2, 3, 4, 5];
let c = v.chunks_mut(2);
assert_eq!(c.last().unwrap()[1], 5);
assert_eq!(c.last().unwrap(), &[4, 5]);

let v2: &mut [i32] = &mut [0, 1, 2, 3, 4];
let c2 = v2.chunks_mut(2);
assert_eq!(c2.last().unwrap()[0], 4);
assert_eq!(c2.last().unwrap(), &[4]);
}

#[test]
Expand Down

0 comments on commit ed77483

Please sign in to comment.