Exemplo n.º 1
0
def proinfomation():
    initdataPath = "../data/initdata.txt"
    res = util.read_line(initdataPath)

    countDic = {}
    for item in res:
        proId = int(item.split()[0])
        pyfilename = os.path.join("../data/", str(proId), "WA_py",
                                  item.split()[1])
        faultLines = list(map(int, item[item.index("[") + 1:-1].split(",")))
        if proId not in countDic.keys():
            countDic[proId] = {
                "Title": "",
                "totalVersion": 0,
                "totalLines": 0,
                "testcaseNum": 0,
                "maxLine": -1,
                "minLine": 9999,
                "countFault": 0
            }
            testcasedir = os.path.join("../data/", str(proId), "TEST_DATA")
            testList = os.listdir(testcasedir)
            countDic[proId]["testcaseNum"] = len(testList) // 2
        countDic[proId]["countFault"] += len(faultLines)
        countDic[proId]["totalVersion"] += 1
        tempcontent = util.read_line(pyfilename)
        countDic[proId]["totalLines"] += len(tempcontent)
        countDic[proId]["maxLine"] = max(countDic[proId]["maxLine"],
                                         len(tempcontent))
        countDic[proId]["minLine"] = min(countDic[proId]["minLine"],
                                         len(tempcontent))

    countDic[3919]["title"] = "Judge triangle"
    countDic[3921]["title"] = "Palindrome"
    countDic[3922]["title"] = "Division"
    countDic[3923]["title"] = "Basketball game"
    countDic[3930]["title"] = "Minimum currency payment problem"
    countDic[3943]["title"] = "Full Permutation"
    countDic[3955]["title"] = "Rotate string"

    countDic[3919][
        "description"] = "determine what kind of triangle it is based on the given three edges"
    countDic[3921][
        "description"] = "write a program to determine if the input string is a palindrome"
    countDic[3922][
        "description"] = "output the result of a/b, the result is rounded off, if b is equal to 0, then output error"
    countDic[3923][
        "description"] = "for each line of input, calulate the player's efficiency value"
    countDic[3930][
        "description"] = "calculate the minimum number of coins required to pay"
    countDic[3943][
        "description"] = "print the permutations of 1 to N are output in lexicographic order"
    countDic[3955][
        "description"] = "judge if the string A and string B are rotated string"

    for item in countDic.items():
        print(item)
Exemplo n.º 2
0
def avg_rank(faultLine, dataFileName):
    dataList = util.read_line(dataFileName)
    res = {}
    res['totLine'] = len(dataList[0].split()) - 1
    for onelineinfo in dataList:
        suslist = onelineinfo.split()
        formular_name = suslist[0]
        suslist = list(map(float, suslist[1:]))
        res[formular_name] = getAVGRank(faultLine, suslist)
    return res
Exemplo n.º 3
0
def work(pyFilePath, testDataDirPath):
    src = pyFilePath
    testDataPath = testDataDirPath
    cov, res = getSrcCov(src, testDataPath)
    print(cov, res)
    list = util.read_line(src)
    lineMax = len(list)
    lineNum, caseNum, casePass, caseFail, siCovCase, siCovPass, siCovFail, siunCovCase, siunCovPass, siunCovFail = CountInfo(
        lineMax, cov, res)
    sus_oc = {}
    sus_tu = {}
    sus_op = {}
    sus_ds = {}
    sus_jac = {}
    for lineIndex in range(1, lineNum + 1):
        sus_oc[lineIndex] = SBFL_Formular.cal_ochiai(caseFail, casePass,
                                                     siCovFail[lineIndex],
                                                     siCovPass[lineIndex],
                                                     siunCovFail[lineIndex],
                                                     siunCovPass[lineIndex])
        sus_tu[lineIndex] = SBFL_Formular.cal_turantula(
            caseFail, casePass, siCovFail[lineIndex], siCovPass[lineIndex],
            siunCovFail[lineIndex], siunCovPass[lineIndex])
        sus_op[lineIndex] = SBFL_Formular.cal_op2(caseFail, casePass,
                                                  siCovFail[lineIndex],
                                                  siCovPass[lineIndex],
                                                  siunCovFail[lineIndex],
                                                  siunCovPass[lineIndex])
        sus_ds[lineIndex] = SBFL_Formular.cal_dstar(caseFail, casePass,
                                                    siCovFail[lineIndex],
                                                    siCovPass[lineIndex],
                                                    siunCovFail[lineIndex],
                                                    siunCovPass[lineIndex], 3)
        sus_jac[lineIndex] = SBFL_Formular.cal_jaccard(caseFail, casePass,
                                                       siCovFail[lineIndex],
                                                       siCovPass[lineIndex],
                                                       siunCovFail[lineIndex],
                                                       siunCovPass[lineIndex])
    return lineNum, sus_oc, sus_tu, sus_op, sus_ds, sus_jac
Exemplo n.º 4
0
def loadInitData():
    initdataPath = "../data/initdata.txt"
    res = util.read_line(initdataPath)
    return res
Exemplo n.º 5
0
                                                  siunCovPass[lineIndex])
        sus_ds[lineIndex] = SBFL_Formular.cal_dstar(caseFail, casePass,
                                                    siCovFail[lineIndex],
                                                    siCovPass[lineIndex],
                                                    siunCovFail[lineIndex],
                                                    siunCovPass[lineIndex], 3)
        sus_jac[lineIndex] = SBFL_Formular.cal_jaccard(caseFail, casePass,
                                                       siCovFail[lineIndex],
                                                       siCovPass[lineIndex],
                                                       siunCovFail[lineIndex],
                                                       siunCovPass[lineIndex])
    return lineNum, sus_oc, sus_tu, sus_op, sus_ds, sus_jac


if __name__ == '__main__':
    src = '../data/check/check2.py'
    testDataPath = '../data/check/testdata1'
    srclist = util.read_line(src)
    lineNum, sus_oc, sus_tu, sus_op, sus_ds, sus_jac = work(src, testDataPath)
    # print(lineNum)
    for i in range(1, lineNum + 1):
        print("%-10s" % ("line " + str(i) + ":"), end=' ')
        # print("%-100s" % (srclist[i-1]), end=' ')
        print("%-15s" % ("sus_oc:" + str(round(sus_oc[i], 5))), end=' ')
        print("%-15s" % ("sus_tu:" + str(round(sus_tu[i], 5))), end=' ')
        print("%-15s" % ("sus_op:" + str(round(sus_op[i], 5))), end=' ')
        print("%-15s" % ("sus_ds:" + str(round(sus_ds[i], 5))), end=' ')
        print("%-15s" % ("sus_jac:" + str(round(sus_jac[i], 5))), )

    # print(sorted(sus_oc.items(), key=lambda x: x[1],reverse=True))
Exemplo n.º 6
0
def work(granularity, pyFilePath, testDataDirPath):
    src = pyFilePath
    testDataPath = testDataDirPath
    mutatePath = './mutant/mutant.py'
    mutateOutPutDir = './mutant_output'
    programOutPutDir = './program_output'
    cov, res, order = getSrcCov(granularity, src, testDataPath, programOutPutDir)
    caseNum = len(res)
    list = util.read_line(src)
    lineMax = len(list)
    mutantcnt = 0
    sus_jac = {}
    sus_oc = {}
    sus_op = {}
    sus_tu = {}
    sus_ds = {}
    vis = {}
    for i in range(1, lineMax + 1):
        sus_jac[i] = 0
        sus_oc[i] = 0
        sus_op[i] = 0
        sus_tu[i] = 0
        sus_ds[i] = 0
        vis[i] = 0
    for i in range(caseNum):
        if res[i] == False:
            for lineIndex in cov[i]:
                if vis[lineIndex] == 1:
                    continue
                vis[lineIndex] = 1
                line = list[lineIndex - 1]
                temp_sus_jac = [0]
                temp_sus_oc = [0]
                temp_sus_op = [0]
                temp_sus_tu = [0]
                temp_sus_ds = [0]
                for key, value in MBFL_Formular.mutation_trick.items():
                    if "#" in line:
                        continue
                    if key in line:
                        for mutation_operator in value:
                            linelen = len(line)
                            pos = 0
                            while pos >= 0 and pos < linelen:
                                pos = line.find(key, pos)
                                if pos == -1:
                                    break
                                newline = line[0:pos] + mutation_operator + line[pos + len(key):]
                                pos += len(key)
                                newlist = list[:]
                                newlist[lineIndex - 1] = newline
                                util.write_file(mutatePath, newlist)
                                if util.CheckCompile(mutatePath):
                                    mutantcnt += 1
                                else:
                                    continue
                                starttime = datetime.datetime.now()
                                temp_cov, temp_res, temp_order = getSrcCov(granularity, mutatePath, testDataPath,
                                                                           mutateOutPutDir)
                                Akf, Anf, Akp, Anp = getInfo(granularity, temp_order, caseNum, res, mutateOutPutDir,
                                                             programOutPutDir)
                                endtime = datetime.datetime.now()
                                logcontent = "%d行%d位置从%s变异到%s %d %d %d %d %s执行%d变异体所耗时间%f" % (
                                    lineIndex, pos, key, mutation_operator, Akf, Anf, Akp, Anp, src, mutantcnt,
                                    (endtime - starttime).seconds)
                                util.logInfo("./REAL_MutantTime.txt", logcontent)

                                temp_sus_jac.append(MBFL_Formular.cal_jaccard(Akf, Anf, Akp, Anp))
                                temp_sus_oc.append(MBFL_Formular.cal_ochiai(Akf, Anf, Akp, Anp))
                                temp_sus_op.append(MBFL_Formular.cal_op2(Akf, Anf, Akp, Anp))
                                temp_sus_tu.append(MBFL_Formular.cal_tarantula(Akf, Anf, Akp, Anp))
                                temp_sus_ds.append(MBFL_Formular.cal_dstar(Akf, Anf, Akp, Anp, 3))
                sus_jac[lineIndex] = max(sus_jac[lineIndex], max(temp_sus_jac))
                sus_oc[lineIndex] = max(sus_oc[lineIndex], max(temp_sus_oc))
                sus_op[lineIndex] = max(sus_op[lineIndex], max(temp_sus_op))
                sus_ds[lineIndex] = max(sus_ds[lineIndex], max(temp_sus_ds))
                sus_tu[lineIndex] = max(sus_tu[lineIndex], max(temp_sus_tu))
    return lineMax, sus_jac, sus_oc, sus_op, sus_tu, sus_ds