← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6075.d.7 · 生成模型:未记录

布尔断言覆盖正反场景

理解等级:中级

assert! 接收布尔条件,条件为假会使测试 panic。预期业务结果为假时写 assert!(!条件)。矩形能否容纳的两种方向都要举例,因为把宽度比较写反后,大装小的正例会失败,原先的小装大反例仍可能通过。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第11章 编写自动化测试(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c11.xhtml`,块 0064) - 结论依据:原文解释了为什么应当对预期为假的 `can_hold` 结果取反。 - 原始内容:Because the correct result of the can_hold function in this case is false, we need to negate that result before we pass it to the assert! macro. As a result, our test will pass if can_hold returns false: