计算下列代码片段的Halstead复杂度的11项内容
if(month < 3){
month = month + 12;
year = year - 1;
}
return dayray((int)(day + (month + 1) * 26/10 + year + year / 4 + 6 * (year/100) + year / 400) % 7);
操作符 | 出现次数 |
---|
if | 1 |
< | 1 |
+= | 1 |
– | 1 |
+ | 6 |
* | 2 |
/ | 4 |
% | 1 |
操作数 | 出现次数 |
---|
month | 3 |
year | 5 |
dayray | 1 |
day | 1 |
3 | 1 |
12 | 1 |
1 | 1 |
26 | 1 |
10 | 1 |
4 | 1 |
6 | 1 |
100 | 1 |
400 | 1 |
7 | 1 |
由两个表格可以得知:n1 = 8, N1 = 16, n2 = 14, N2 = 20;
- Halstead 程序词汇表长度 Program vocabulary: n = n 1 + n 2 = 8 + 14 = 22
- Halstead 程序长度或简单长度 Program length: N = N1 + N2 = 16 + 20 = 36
- 以 N^ 表示程序的预测长度 Calculated program length: N^ = n1log2(n1) + n2log2(n2) = 8
*
log2(8) + 14 *
log2(14) = 77.3 - 程序体积或容量 Volume: V = Nlog2(n) = 36 * log2(22) = 160.5384
- 程序级别 Level: L^ = (2/n1)(n2/N2) = (2/8)(14/20) = 2.8
- 程序难度 Difficulty: D = 1/L^ = 1/2.8 = 0.357
- 编程工作量 Effort:E = V * D = 160.5384 * 0.357 = 57.3122088
- 语言级别: Lʹ = L^ * L^ * V = 2.8 * 2.8 * 160.5384 = 1258.62106
- 编程时间 (hours): T^ = E/(S * f) = 57.3122088/(3600*18) = 0.00088445
- 平均语句大小: N/语句数 = 36 / 5 = 7.2
- 程序中的错误数预测值: B = V/3000 = 160.5384/3000 = 0.0535128