iterators3 tests dont check if errors are returned correctly

Aperta
#2,207 4 commenti 1 reazione 0 assegnatari Vedi su GitHub

@Lars-Schumann ci sta già lavorando.

Dal 24/2/2025.

  • #2212 di @Lars-Schumann — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
testing-qa

Direzione di ricerca

Inizia da exercises/18_iterators/iterators3.rs e dai test esistenti; confronta le relative asserzioni con la soluzione di filtraggio descritta nell’issue. Aggiorna l’esercizio o i suoi input di test in modo che un’implementazione che scarta le varianti Err fallisca, e verifica che il comportamento previsto di Result sia coperto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

A-exercises C-enhancement P-medium

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.

Lingua principale
Rust
Stelle
64.8k
Fork
11.3k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-lang/rustlings

Tutte le issue di rust-lang/rustlings

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.