iterators3 tests dont check if errors are returned correctly

未关闭
#2,207 4 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

@Lars-Schumann 已经在做这个了。

开始于 2025年2月24日。

  • #2212 来自 @Lars-Schumann —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
rust
领域
testing-qa

调研方向

从 exercises/18_iterators/iterators3.rs 及其现有测试开始;将其中的断言与 issue 中描述的过滤解决方案进行比较。更新练习或其测试输入,使丢弃 Err 变体的实现失败,并验证预期的 Result 行为已得到覆盖。

由索引模型根据 Issue 内容生成。

描述

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.

主要语言
Rust
星标
64.8k
派生
11.3k
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-lang/rustlings 的其他 Issue

查看 rust-lang/rustlings 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。