软件测试(四)

// 计算下列代码片段的 Halstead 复杂度的11项内容:
if (month < 3) { 
		month += 12; 
  	--year; 
}
 
return dayray((int)(day+(month+1)*26/10+year+year/4+6*(year/100)+year/400)%7); 

\(n_1\)表示程序中不同操作符的个数
\(n_2\)表示程序中不同操作数的个数
\(N_1\)表示程序中出现操作符的总数
\(N_2\)表示程序中出现操作数的总数

Operator Number of Occurrences Operand Number of Occurrences Operand Number of Occurrences
\(if\) 1 month 3 10 1
\(<\) 1 year 5 4 1
\(+=\) 1 dayray 1 6 1
\(--\) 1 day 1 100 1
\(+\) 5 3 1 400 1
\(*\) 2 12 1 7 1
\(/\) 4 1 1
\(\%\) 1 26 1
\(n_1=8\) \(N_1=16\) \(n_2=14\) \(N_2=20\)
  1. Halstead程序词汇表长度Program vocabulary: \(n=n_1+n_2=22\)
  2. Halstead程序长度或简单长度Program length:\(N=N_1+N_2=36\)
  3. 程序的预测长度:\(N\)^\(=n_1log_2n_1+n_2log_2n_2=53.5823\)
  4. 程序的容量Volumn:\(V=Nlog_2(n)=160.54\)
  5. 程序级别Level:\(L\)^=\((2/n_1) \times (n_2/N_2)=0.175\)
  6. 程序难度Difficulty:\(D=1/L\)^\(=5.714\)
  7. 编程工作量Effort:\(E=V \times D=V/L\)^=\(917.326\)
  8. 语言级别:\(L'=L\)^\(\times L\)^\(\times V=4.917\)
  9. 编程时间(hours):\(T\)^=\(E/(S \times f)=917.326 / (60 \times 60 \times 18)=0.0141h\)
  10. 平均语句大小:\(N/语句数=36/4=9\)
  11. 程序中错误数预测值:\(B=V/3000=Nlog_2(n)/3000=0.0535\)
posted @ 2019-05-24 15:40  Alva112358  阅读(241)  评论(0编辑  收藏  举报