- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
毕竟,我们通常必须说明函数返回的内容;也就是说,如果我们从函数返回一个值,我们总是对返回值做出 promise (否则调用者会期望什么)。
int area(int lenght, int width)
// pre-conditions : lenght and width are positive
// post-condition : returns a positive value that is the area
{
if (lenght <= 0 || width <= 0) error("area() pre-condition");
int a = lenght * width;
if (a <= 0) error("area() post-condition");
return a;
}
这是一个使用前置条件和后置条件的简单示例,但我无法理解的是作者在展示示例后所说的内容:
"We couldn't check the complete post-condition, but we checked the part that said that it should be positive".
这是什么意思?为什么我们不能检查完整的后置条件?根据我的理解,在这种情况下,作为后置条件,我们只需要检查变量 a 是否为正,我错了吗?
作者问我这个问题:
Find a pair of value so that the pre-condition of this version of area holds, but the post-condition doesn't.
不是不可能吗??
最佳答案
In my understanding in this case as post-condition we just need to check that the variable a is positive, am I wrong ?
是的。注意完整的后置条件...
returns a positive value that is the area
可以传递 length
和 width
的值,这样 a
就不会因为溢出而到达正确的区域。
关于c++ - C++ 中的前置条件和后置条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28416392/
我是编程和这个网站的新手,我正在研究 UML 设计的一些术语,我正在寻找基本的回应。我查了每个术语的定义,但我仍然试图掌握这个概念。 最佳答案 前提条件是在调用用例之前必须为真的东西。例如用例“在网站
我有以下变更集: 我想检查唯一约束是否已经存在: select distinct CONSTRAINT_NAME from information_schema.TABLE_C
我是一名优秀的程序员,十分优秀!