mirror of
https://github.com/google/comprehensive-rust.git
synced 2024-11-21 13:25:53 +02:00
Simplify iterator method chaining exercise (#2427)
The exercise is about iterators, _not_ generic integer types. The `where` syntax has also not been introduced before, further adding confusion for the students.
This commit is contained in:
parent
61407e6079
commit
a387b2c755
@ -20,10 +20,7 @@
|
||||
/// wrapping around from the end of `values` to the beginning.
|
||||
///
|
||||
/// Element `n` of the result is `values[(n+offset)%len] - values[n]`.
|
||||
fn offset_differences<N>(offset: usize, values: Vec<N>) -> Vec<N>
|
||||
where
|
||||
N: Copy + std::ops::Sub<Output = N>,
|
||||
{
|
||||
fn offset_differences(offset: usize, values: Vec<i32>) -> Vec<i32> {
|
||||
// ANCHOR_END: offset_differences
|
||||
let a = (&values).into_iter();
|
||||
let b = (&values).into_iter().cycle().skip(offset);
|
||||
@ -46,14 +43,6 @@ fn test_larger_offsets() {
|
||||
assert_eq!(offset_differences(5, vec![1, 3, 5, 7]), vec![2, 2, 2, -6]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_custom_type() {
|
||||
assert_eq!(
|
||||
offset_differences(1, vec![1.0, 11.0, 5.0, 0.0]),
|
||||
vec![10.0, -6.0, -5.0, 1.0]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_degenerate_cases() {
|
||||
assert_eq!(offset_differences(1, vec![0]), vec![0]);
|
||||
|
Loading…
Reference in New Issue
Block a user