Exemple #1
0
def ochiaiList(dirPosition):
    answerList = calculatorPublic.getAnswer(dirPosition)
    gcovList = calculatorPublic.getGcov(dirPosition, 1).T
    ef = calculatorPublic.getEF(gcovList, answerList)
    ep = calculatorPublic.getEP(gcovList, answerList)
    nf = calculatorPublic.getNF(gcovList, answerList)
    return ef / numpy.sqrt((ef + nf) * (ef + ep))
Exemple #2
0
def jaccardList(dirPosition):
    answerList = calculatorPublic.getAnswer(dirPosition)
    gcovList = calculatorPublic.getGcov(dirPosition, 1).T
    ef = calculatorPublic.getEF(gcovList, answerList)
    ep = calculatorPublic.getEP(gcovList, answerList)
    nf = calculatorPublic.getNF(gcovList, answerList)
    return 1 / (1 + (ep + nf) / ef)
Exemple #3
0
def tarantulaList(dirPosition):
    answerList = calculatorPublic.getAnswer(dirPosition)
    gcovList = calculatorPublic.getGcov(dirPosition, 1).T
    ef = calculatorPublic.getEF(gcovList, answerList)
    ep = calculatorPublic.getEP(gcovList, answerList)
    tf = calculatorPublic.getTF(answerList)
    tp = calculatorPublic.getTP(answerList, tf)
    return 1 / (1 + (numpy.dot(ep, tf)) / (numpy.dot(ef, tp)))
Exemple #4
0
def networks(dirPosition, times):
    answerList = calculatorPublic.getAnswer(dirPosition)
    gcovList = calculatorPublic.getGcov(dirPosition, times)
    training(dirPosition, answerList, gcovList)
    model = tf.keras.models.load_model(dirPosition +
                                       '/numpyDataDir/myModel.h5')
    testList = numpy.identity(len(gcovList[0]))
    return model.predict(testList)
Exemple #5
0
def FLSFList(dirPosition):
    answerList = calculatorPublic.getAnswer(dirPosition)
    gcovList = calculatorPublic.getGcov(dirPosition, 2).T
    fs = calculatorPublic.getFS(gcovList, answerList)
    ps = calculatorPublic.getPS(gcovList, answerList)
    tf = calculatorPublic.getTF(answerList)
    tp = calculatorPublic.getTP(answerList, tf)
    res = []
    r1 = []
    r2 = []
    for i in range(0, len(fs)):
        temp1 = 0
        temp2 = 0
        for j in range(0, len(fs[0])):
            try:
                flag1 = math.exp(fs[i][j] * 0.6)
            except OverflowError:
                flag1 = float('inf')
            try:
                flag2 = math.exp(-fs[i][j] * 0.6)
            except OverflowError:
                flag2 = 0
            temp1 = temp1 + (flag1 - flag2) / (flag1 + flag2)
        r1.append(temp1)
        for k in range(0, len(ps[0])):
            try:
                flag1 = math.exp(ps[i][k] * 0.6)
            except OverflowError:
                flag1 = float('inf')
            try:
                flag2 = math.exp(-ps[i][k] * 0.6)
            except OverflowError:
                flag2 = 0
            temp2 = temp2 + (flag1 - flag2) / (flag1 + flag2)
        r2.append(temp2)
        temp4 = r2[i] * tf
        temp5 = r1[i] * tp
        if temp5 == 0:
            if temp4 == 0:
                res = numpy.append(res, 1)
            else:
                res = numpy.append(res, 0)
        else:
            temp3 = 1 / (1 + temp4 / temp5)
            res = numpy.append(res, temp3)
    return res
Exemple #6
0
def dbscan(dirPosition):
    # tarantula算法得到结果
    initList = tarantula.tarantulaList(dirPosition)
    # 前20%怀疑度矩阵
    rankList = calculatorPublic.getResultList(initList)
    # 将rankList矩阵装换为list类型方便之后计算等操作
    rank = getRank(rankList)
    # 程序是否通过的列表
    answerList = calculatorPublic.getAnswer(dirPosition)
    # 程序运行轨迹gcov矩阵
    gcovList = calculatorPublic.getGcov(dirPosition, 1)
    # 记录未通过测试用例编号(真实编号-1)
    unPassList = []
    # 未通过测试用例是否执行被怀疑语句的记录矩阵
    initMap = []
    # 获取记录矩阵(initMap)
    for i in range(answerList.__len__()):
        if answerList[i] == 0:
            temp = []
            unPassList.append(i)
            for item in rank:
                if gcovList[i][item] == 1:
                    temp.append(item)
            if temp.__len__() != 0:
                initMap.append(temp)
    # 获取参数1:每个错误测试用例所包含的怀疑度行与怀疑度行总数的百分比
    parameter_x = getParameter_x(initMap, rank)
    # 获取参数2:每个错误测试用例的轨迹相对于第一个测试用例轨迹的变化值
    parameter_y = getParameter_y(gcovList, unPassList)
    # 对参数1和参数2进行整合形成一个对应的坐标矩阵
    parameterMap = getParameterMap(parameter_x, parameter_y)
    # 对得到的坐标矩阵进行DBSCAN聚类操作得到分类列表
    clusteringList = getClusteringList(parameterMap)
    # 对得到的分簇list进行分解
    dbscanTestNumber = getDbscanTestNumber(clusteringList, unPassList)
    print("dbscan:" + str(dbscanTestNumber.__len__()))
    # 对得到的结果进行存放
    numpy.save(dirPosition + "/numpyDataDir/dbscanTestNumber.npy",
               dbscanTestNumber)
Exemple #7
0
def tarantula(dirPosition, testsList):
    # 载入源数据中的测试结果
    answerList = calculatorPublic.getAnswer(dirPosition)
    # 载入源数据中的gcov图谱集
    gcovList = calculatorPublic.getGcov(dirPosition, 1)
    # 存放本次计算需要的测试结果集
    answer = []
    # 存放本次计算需要的gcov图谱集
    gcov = []
    # 获取对应于testsList中所包含的测试用例的测试结果
    for test in testsList:
        answer.append(answerList[test])
        gcov.append(gcovList[test])
    # 将answer和gcov两个list都转换为numpy矩阵类型
    answer = numpy.array(answer)
    gcov = numpy.array(gcov)
    # 对gcov进行翻转
    gcov = gcov.T
    ef = calculatorPublic.getEF(gcov, answer)
    ep = calculatorPublic.getEP(gcov, answer)
    tf = calculatorPublic.getTF(answer)
    tp = calculatorPublic.getTP(answer, tf)
    return 1 / (1 + (numpy.dot(ep, tf)) / (numpy.dot(ef, tp)))
Exemple #8
0
def init(dirPosition):
    # tarantula算法得到结果
    initList = tarantula.tarantulaList(dirPosition)
    # 前20%怀疑度矩阵
    rankList = calculatorPublic.getResultList(initList)
    # 程序是否通过的列表
    answerList = calculatorPublic.getAnswer(dirPosition)
    # 程序运行轨迹gcov矩阵
    gcovList = calculatorPublic.getGcov(dirPosition, 1)
    # 记录未通过测试用例编号(真实编号-1)
    unPassList = []
    # 未通过测试用例是否执行被怀疑语句的记录矩阵
    initMap = []
    # 获取记录矩阵(initMap)
    for i in range(answerList.__len__()):
        if answerList[i] == 0:
            temp = []
            unPassList.append(i)
            for j in range(rankList.__len__()):
                for k in range(rankList[j].__len__()):
                    if gcovList[i][rankList[j][k]] == 1:
                        temp.append(rankList[j][k])
            if temp.__len__() != 0:
                initMap.append(temp)
    # 相似度矩阵
    similarMap = []
    # 获取相似度矩阵
    for i in range(initMap.__len__()):
        temp = []
        for j in range(initMap.__len__()):
            if i == j:
                temp.append(0)
            else:
                # 获取交集
                len1 = list(set(initMap[i]).intersection(set(initMap[j]))).__len__()
                # 获取并集
                len2 = list(set(initMap[i]).union(set(initMap[j]))).__len__()
                temp.append(len1 / len2)
        similarMap.append(temp)
    # 存放簇
    cuMap = [[0]]
    # 获取簇(cuMap)
    for i in range(similarMap.__len__()):
        position = check(cuMap, i)
        if position == -1:
            maxnum = 0
            site = 0
            for j in range(cuMap.__len__()):
                for k in range(cuMap[j].__len__()):
                    if similarMap[cuMap[j][k]][i] > maxnum:
                        maxnum = similarMap[cuMap[j][k]][i]
                        site = j
            if maxnum >= 0.7:
                cuMap[site].append(i)
            else:
                cuMap.append([i])
    # 存放簇中对应的测试用例编号(实际编号-1的值)
    testNumberMap = []
    # 将簇中对应编号进行转换
    for i in range(cuMap.__len__()):
        temp = []
        for j in range(cuMap[i].__len__()):
            temp.append(unPassList[cuMap[i][j]])
        testNumberMap.append(temp)
    print("clustering:" + str(testNumberMap.__len__()))
    # 将分簇后的测试用例编号矩阵(testNumberMap)进行物理存储
    numpy.save(dirPosition + "/numpyDataDir/testNumberMap.npy", testNumberMap)