Skip to content

Commit

Permalink
Fix tests 3: group to chunk (variables)
Browse files Browse the repository at this point in the history
Remain `grouper`, rename it to what?
  • Loading branch information
Philippe-Cholet committed Jan 31, 2024
1 parent 734ab42 commit 0393dc5
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions tests/test_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,23 +892,23 @@ fn chunk_by_lazy_2() {

let grouper = data.iter().chunk_by(|k| *k);
let mut chunks = Vec::new();
for (k, group) in &grouper {
for (k, chunk) in &grouper {
if *k == 1 {
chunks.push(group);
chunks.push(chunk);
}
}
it::assert_equal(&mut chunks[0], &[1, 1]);

let data = [0, 0, 0, 1, 1, 0, 0, 2, 2, 3, 3];
let grouper = data.iter().chunk_by(|k| *k);
let mut chunks = Vec::new();
for (i, (_, group)) in grouper.into_iter().enumerate() {
for (i, (_, chunk)) in grouper.into_iter().enumerate() {
if i < 2 {
chunks.push(group);
chunks.push(chunk);
} else if i < 4 {
for _ in group {}
for _ in chunk {}
} else {
chunks.push(group);
chunks.push(chunk);
}
}
it::assert_equal(&mut chunks[0], &[0, 0, 0]);
Expand All @@ -922,30 +922,30 @@ fn chunk_by_lazy_2() {
i += 1;
k
});
for (i, group) in &grouper {
for (i, chunk) in &grouper {
match i {
0 => it::assert_equal(group, &[0, 0, 0]),
1 => it::assert_equal(group, &[1, 1, 0]),
2 => it::assert_equal(group, &[0, 2, 2]),
3 => it::assert_equal(group, &[3, 3]),
0 => it::assert_equal(chunk, &[0, 0, 0]),
1 => it::assert_equal(chunk, &[1, 1, 0]),
2 => it::assert_equal(chunk, &[0, 2, 2]),
3 => it::assert_equal(chunk, &[3, 3]),
_ => unreachable!(),
}
}
}

#[test]
fn chunk_by_lazy_3() {
// test consuming each group on the lap after it was produced
// test consuming each chunk on the lap after it was produced
let data = [0, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2];
let grouper = data.iter().chunk_by(|elt| *elt);
let mut last = None;
for (key, group) in &grouper {
for (key, chunk) in &grouper {
if let Some(gr) = last.take() {
for elt in gr {
assert!(elt != key && i32::abs(elt - key) == 1);
}
}
last = Some(group);
last = Some(chunk);
}
}

Expand Down

0 comments on commit 0393dc5

Please sign in to comment.