rust-lang / rust-lang/rustlings
iterators3 tests dont check if errors are returned correctly
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 64.2k
- Forks
- 11.3k
- Avg merge
- 5h 24m
- Merged PRs (30d)
- 2
Description
I'm currently doing rustlings and struggled with iterators3 and searched a solution, which i thought i found here.
It implements one of the functions to edit like this:
fn result_with_list() -> Result<Vec<i64>, DivisionError> {
let numbers = vec![27, 297, 38502, 81];
let division_results = numbers.into_iter().map(|n| divide(n, 27));
division_results.filter(|x| x.is_ok()).collect()
}
which compiles and passes the implemented test but this didn't make any sense to me, as this can never return a correct Err variant, at "best" this would return and empty Vec<i64>, if every division returns an Err variant, which is, as far as i understand, not the intended solution.
To remedy this, I would suggest adding test cases to cover this wrong solution, but since the functions that get tested here don't take any parameters, but instead have hard-coded values inside them, this would require changing their signature and passing in the vector of numbers to be divided.
I'm new to rust, so please let me know if this isn't a real issue.
If this is indeed a real issue, I'm happy to suggest an updated version of this exercise.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with exercises/18_iterators/iterators3.rs and its existing tests; compare their assertions with the filtering solution described in the issue. Update the exercise or its test inputs so an implementation that discards Err variants fails, and verify that the intended Result behavior is covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100