题目
计算下列代码片段的 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);
答案
-
操作符
Operator Number of Occurrences Operator Number of Occurrences if 1 + 6 < 1 * 2 += 1 / 4 - 1 % 1 return 1 dayray 1 int 1 n1=11 N1=20 -
操作数
Operand Number of Occurrences Operand Number of Occurrences month 3 26 1 3 1 10 1 12 1 4 1 year 5 6 1 day 1 100 1 1 1 400 1 7 1 n2=13 N2=19 -
计算
- 词汇表长度(Program vocabulary ):n = n1+n2 = 24
- 程序长度或简单长度(Program length ):N = N1+N2 = 39
- 程序的预测长度(Calculated program length):N^ = 11*log2(11)+13*log2(13)=86.1594641399
- 程序体积或容量(Volume ):V=N*log2(n)= 39*log2(24)= 178.8135375273
- 程序级别(Level ):L^ = (2/n1)*(n2/N2)= (2/11)*(13/19)=0.1244019138755980861244019138756
- 程序难度(Difficulty ):D = 1/L^ = 8.0384615384615384615384615384614
- 编程工作量(Effort ):E = V*D = 1437.38574396945
- 语言级别:L’ = L*L*V = 2.7672890128077379180879558618164
- 编程时间(hours ):T^ = E/(S*F) = 0.02218187876496064814814814814815
- 平均语句大小:N / 语句数 = 39/4 = 9.75
- 程序中的错误数预测值:B = V / 3000 = 0.0596045125091