免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2702 | 回复: 1
打印 上一主题 下一主题

mcdc generator [复制链接]

论坛徽章:
2
辰龙
日期:2013-09-24 12:26:05卯兔
日期:2013-09-24 12:27:37
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-02-27 14:49 |只看该作者 |倒序浏览
测试需要Modified condition/decision coverage (MC/DC - MCDC)
如:
if ( (A || B) && C )
{
/* instructions */
}
else
{
/* instructions */
}

mcdc 需要4个case, 变量个数+1 (3+1)
1.A = false/ B = false / C = true   --->  decision is evaluated to "false"
2.A = false / B = true  / C = true   --->  decision is evaluated to "true"
3.A = false / B = true  / C = false  --->  decision is evaluated to "false"
4.A = true  / B = false / C = true   --->  decision is evaluated to "true

Modified condition/decision coverage which implies that each boolean variable should be evaluated one time to "true" and one time to "false", and this with affecting the decision's outcome. It means that from a test case to another, changing the value of only one atomic condition will also change the decision's outcome(每个变量单独影响输出);

想写个算法自动生成出来如:
--a----b----c--      result
--F----F----T--         F
--T----F----T--         T
--F----T----F--         F
--F----T----T--         T

求指导啊:wink:




论坛徽章:
2
辰龙
日期:2013-09-24 12:26:05卯兔
日期:2013-09-24 12:27:37
2 [报告]
发表于 2014-02-27 19:19 |只看该作者
本帖最后由 chenxing0407 于 2014-02-27 19:19 编辑

对于简单的如 a&b&c, 我有点思路:
abc三个变量,对应二进制 111,
然后用111分别减去每位对应的权重,就能得到对应的标志
如:
  1. exp = "a&b&c"
  2. elements = exp.translate(None,"&")

  3. ele_len = len(elements)
  4. i = max =0
  5. while i < ele_len:
  6.         max += 2**i
  7.         i += 1

  8. result = [bin(max)]
  9. i = 0
  10. while i < ele_len:
  11.         tmp = max - 2**i
  12.         result.append(bin(tmp))
  13.         i += 1

  14. final_result = [ ele.lstrip('0b').zfill(ele_len) for ele in result]
  15. print final_result
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP