面向源代码的软件可信度量模型 T n a T_{na} Tna
课程:软件质量分析
作业
可编写下面的java程序:
package org.example;
public class SourceCodeOrientedModel {
public static void main(String[] args) {
int total = 41;
int[] m = {9, 22, 9, 5, 7, 10, 17, 27};
double[] k = {(double)2 / 9, (double)2 / 9, (double)1 / 8, (double)1 / 13, (double)1 / 12, (double)2 / 9, (double)2 / 11, (double)1 / 11};
double[] p = {0.8, 0.6, 0.4, 0.2, 0.1, 0.01, 0.001};
double[] weights = new double[m.length];
for (int i = 0; i < m.length; i++) {
weights[i] = (double)m[i] / total;
}
for (int i = 0; i < p.length; i++) {
double trustworthiness = softwareTrustworthinessMeasureTna(weights, k, p[i]);
System.out.println("For p = " + p[i] + ", the software trustworthiness measure is " + trustworthiness);
}
}
public static double softwareTrustworthinessMeasureTna(double[] weights, double[] k, double p) {
double result = 0.0;
for (int i = 0; i < weights.length; i++) {
result += weights[i] * Math.pow(10 * Math.pow(k[i], p), p);
}
return Math.pow(result, 1 / p);
}
}
运行结果
For p = 0.8, the software trustworthiness measure is 7.3246342511116165
For p = 0.6, the software trustworthiness measure is 15.607696281400395
For p = 0.4, the software trustworthiness measure is 49.9882487827009
For p = 0.2, the software trustworthiness measure is 786.1135952531853
For p = 0.1, the software trustworthiness measure is 110038.2634022844
For p = 0.01, the software trustworthiness measure is 1.753191883427931E42
For p = 0.001, the software trustworthiness measure is Infinity