Too forgiving test in `rpn-calculator-inspection`
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- elixir
- 领域
- testing-qa
调研方向
从 RPNCalculatorInspection.reliability_check/2 的练习测试开始,并运行现有测试套件。将它们与提供的 200/150/0 回归案例进行比较,然后确定是否应更改测试或练习的范围。完成的标准是:已覆盖约定的 timeout 行为,同时没有让解决方案超出该练习的教学范围。
由索引模型根据 Issue 内容生成。
描述
Tests for RPNCalculatorInspection.reliability_check/2 are too forgiving for calculations that take longer than 100ms. If the solution starts the checks in parallel and awaits the results iteratively all the tests pass, but they should not. When the solution awaits the first check and it does not complete in 100ms, it adds :timeout to results. But when awaiting the second check, it already has that 100ms "bonus" from the previous await. So if the second check takes 150ms to finish, the await will receive the response after 50ms and add :ok to results, whereas it should add :timeout.
Here is a test which covers this case:
test "returns :timeout for all calculations lasting longer than 100ms" do
inputs = [200, 150, 0]
calculator = &:timer.sleep(&1)
outputs = %{
200 => :timeout,
150 => :timeout,
0 => :ok
}
assert RPNCalculatorInspection.reliability_check(calculator, inputs) == outputs
end
And here is a solution which passes the existing tests, but not the above one:
def reliability_check(calculator, inputs) do
trap_orig = Process.flag(:trap_exit, true)
results =
inputs
|> Enum.map(&start_reliability_check(calculator, &1))
|> Enum.reduce(%{}, &await_reliability_check_result/2)
Process.flag(:trap_exit, trap_orig)
results
end
Here's a solution which will pass the above test as well.
def reliability_check(calculator, inputs) do
trap_orig = Process.flag(:trap_exit, true)
caller = self()
results =
inputs
|> Enum.map(fn input ->
await_pid =
spawn_link(fn ->
check = start_reliability_check(calculator, input)
results = await_reliability_check_result(check, %{})
[{^input, result}] = Map.to_list(results)
send(caller, {self(), result})
end)
{input, await_pid}
end)
|> Enum.reduce(%{}, fn {input, await_pid}, results ->
receive do
{^await_pid, result} -> Map.put(results, input, result)
after
200 -> raise "Timeout"
end
end)
Process.flag(:trap_exit, trap_orig)
results
end
Hardening the test would lead to more complicated solutions which are probably beyond the educational scope of this exercise. But the existing tests do not sufficiently cover the goals set in the exercise. So I'm not sure what exactly to do here.
- 主要语言
- Elixir
- 星标
- 665
- 派生
- 415
- 平均合并
- 13 小时 3 分钟
- 30 天内合并 PR
- 12
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
exercism/elixir 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
48in24 Approaches for Raindrops可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 5/5 一周以上 新手友好度 25/100
exercism/elixir#1420 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
exercism/elixir#1162 · 1 条评论 ·
维护者通常 1 天内回复
-
x:action/sync x:knowledge/intermediate x:module/practice-exercise x:size/medium x:type/content
难度 4/5 3-5 天 新手友好度 35/100
exercism/elixir#1027 · 4 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
intellij-elixir/intellij-elixir#4782 ·
维护者通常 1 天内回复
-
level 2 wocs
难度 1/5 1 小时以内 新手友好度 90/100
phravins/QuantumBilling#51 ·
-
fix(ocr): compile the Tesseract-free pipeline with Tokio runtime可能已有人在做 @Goldziher 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
carverauto/serviceradar#6898 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
elixir-ecto/myxql#221 ·