corner case和edge case的差别

编程入门 行业动态 更新时间:2024-10-08 20:32:30

corner case和edge case的<a href=https://www.elefans.com/category/jswz/34/1766741.html style=差别"/>

corner case和edge case的差别

一、引言

在网上看到了1个很有意思的问题,先贴一下问题和高分回答,附原链接:What is the difference between an edge case and a corner case?

I've seen the two terms use interchangeably. Definitions found online seem to vary as well.

From my understanding, a corner case is the extreme values of inputs. And edge cases are the extreme cases to handle when designing an algorithm. Is this correct?

Is there a standard definition?

These are often used interchangeably. If you're being careful about language, these have specific (engineering) meanings (courtesy of Wikipedia):

In engineering, a corner case (or pathological case) involves a problem or situation that occurs only outside of normal operating parameters—specifically one that manifests itself when multiple environmental variables or conditions are simultaneously at extreme levels, even though each parameter is within the specified range for that parameter.

An edge case is a problem or situation that occurs only at an extreme (maximum or minimum) operating parameter. For example, a stereo speaker might noticeably distort audio when played at its maximum rated volume, even in the absence of other extreme settings or conditions.

In programming, an edge case typically involves input values that require special handling in an algorithm behind a computer program. As a measure for validating the behavior of computer programs in such cases, unit tests are usually created; they are testing boundary conditions of an algorithm, function or method. A series of edge cases around each "boundary" can be used to give reasonable coverage and confidence using the assumption that if it behaves correctly at the edges, it should behave everywhere else.

For example, a function that divides two numbers might be tested using both very large and very small numbers. This assumes that if it works for both ends of the magnitude spectrum, it should work correctly in between.

二、引发的思考

到底什么是edge用例,什么是corner测试(特殊、极端场景?),他们似乎都可以被中文翻译成边界用例,认为是边界值测试的一种。

参考维基百科的说明:边角案例

边角案例(corner case)或病态案例(pathological case)是指其操作参数在正常范围以外的问题或是情形,而且多半是几个环境变数或是条件都在极端值的情形,即使这些极端值都还在参数规格范围内(或是边界),也算是边角案例。

边角案例(corner case)和边缘案例(edge case)不同,边缘条件只是单一个变数为最大值或最小值。若某个扬音器只要音量最大,不论其他条件是否正常或是极端,声音都会扭曲,这是边缘案例。

边角案例(corner case)一词来自边缘案例(edge case),边缘案例是指一个参数或是条件为极值,二个边缘的交点即为角,因此边角案例就是数个参数或是条件均为极值的情形。

这么看下来,大部分的解释最终都落在了影响结果的变量数量;

(1)边缘用例(edge case)

如果只是单一的变量取值超出了常规范围,引发了异常场景,就可以叫做边缘用例,对应了测试方法中常用的边界值测试。

举个例子,a = b mod c,我们都知道c的值应该>0或<0,测试c=0的场景便是一种边缘用例。

(2)边角用例(corner case)

多个变量进行组合,多个变量的取值都超出了常规范围,引发了异常场景,就叫做边角用例。这样的组合通常情况下都是不可预计的,难以从正向分析的角度给出明确的结论,尽管这样的变量组合有可能在写代码时就明确并给出说明,但是随着软件复杂度的提升,这样的正向分析的成本和要求都愈加提高。

继续上面的例子,如果表达式变成下面这样,正向分析时我们认为应该测试c = 0和e = 0的场景,却遗漏了,如果b = 0的时候会导致a被赋值0,从而让e直接等于0,是否能够覆盖这样的场景,就需要我们测试人员对正向的实现进行更加详尽的分析。

或者,我们需要借助其他的方法进行测试,比如自动生成测试数据注入的工具,借助混沌测试这样的方法论,辅助我们了解系统在不同组合场景的输入情况下能够给出怎样的反应。

a = b mod ce = ac = d mod e

更多推荐

corner case和edge case的差别

本文发布于:2024-02-27 22:04:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1766758.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:差别   corner   case   edge

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!