使用PICS进行测试,但测试用例不完整

时间:2014-10-10 13:56:33

标签: testing

我正在测试PICT中的三角形问题。我测试三角形是等边三角形,等腰三角形还是斜角三角形。问题是我从来没有得到等边三角形。

Side1:        5,6,7,8,9,10
Side2:        5,6,7,8,9,10
Side3:        5,6,7,8,9,10
Type:         equilateral, isosceles, scalene

IF (([Side1] = [Side2]) OR ([Side2] = [Side3]) OR ([Side3] = [Side1])) THEN [Type] = "isosceles"  ELSE [Type] = "scalene";
IF (([Side1] = [Side2]) AND ([Side2] = [Side3]) AND ([Side3] = [Side1])) THEN [Type] = "equilateral";

但随机的是当我将最后一行改为

IF (([Side1] = [Side2]) AND ([Side2] = [Side3]) AND ([Side3] = [Side1])) THEN [Type] = "isosceles";

我随机得到会导致等边三角形的值。我怎样才能确保我的代码中也包含这些值?

2 个答案:

答案 0 :(得分:1)

试试这个:

Side1:        5,6,7,8,9,10
Side2:        5,6,7,8,9,10
Side3:        5,6,7,8,9,10
Type:         equilateral, isosceles, scalene

IF (([Side1] = [Side2] AND [Side2] <> [Side3]) OR ([Side2] = [Side3] AND [Side3] <> [Side1]) OR ([Side3] = [Side1] AND [Side1] <> [Side2])) THEN [Type] = "isosceles";
IF (([Side1] = [Side2]) AND ([Side2] = [Side3])) THEN [Type] = "equilateral";
IF ([Side1] <> [Side2] AND [Side2] <> [Side3] and [Side3] <> [Side1]) THEN [Type] = "scalene";

原因是你的逻辑在案例之间重叠,你应该明确你的条件,例如每个案例只有一个结果。上面的例子有效;我验证了它。祝你好运!

答案 1 :(得分:0)

您必须使用PICT中提供的无条件约束(不变量)

在这种情况下,您必须替换此行

IF (([Side1] = [Side2]) AND ([Side2] = [Side3]) AND ([Side3] = [Side1])) THEN [Type] = "equilateral";

这一个:

[Side1] = [Side2] and [Side2] = [Side3] and [Side3] = [Side1];

因此,生成的测试集将包含至少1个等边三角形。

有关详细信息,请参阅文档:http://www.amibugshare.com/pict/help.html