Commit 5eb1ddbc authored by Kevin Bi's avatar Kevin Bi
Browse files

"Created a new dir tarantula with all the classes neccessary for using the...

"Created a new dir tarantula with all the classes neccessary for using the TarantulaSuspiciousnessCalculation program"
parent 653d50ab
Loading
Loading
Loading
Loading

tarantula/Runner.java

0 → 100644
+42 −0
Original line number Diff line number Diff line
package TarantulaCalculator;

import java.util.ArrayList;
import java.util.List;
 
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
 
public class Runner {
	/**Holds a list of all the tests numbers that fail **/
    private ArrayList<Integer> failCases;
    
    /**Holds the results from the test program**/
    Result result;
     
    public Runner(){}
     
    @SuppressWarnings("rawtypes")
    /**Initialize a Runner object**/
    public Runner(Class testClass){
        failCases = new ArrayList<Integer>();
        result = JUnitCore.runClasses(testClass);
    }
    
    /**Loops through all the failures in result and gets the test header
     * pre: all the test headers must in the format: test# e.g: test1, test 10 
     * post: adds the test header integer segment to the failCases **/
    public void determineFailCases(){
        for (Failure failure : result.getFailures()) {
            String header = failure.getTestHeader();
            String header_segment = header.substring(0, header.indexOf("("));
            String test_case_num = header.substring(4, header_segment.length());
            failCases.add(Integer.parseInt(test_case_num));
        }
    }   
     
    /**Return the list of the fail cases**/
    public ArrayList<Integer> getFailCases(){
        return failCases;
    }
}
+67 −0
Original line number Diff line number Diff line
package TarantulaCalculator;

import java.util.Arrays;
import java.io.File;
import java.util.ArrayList;
 
public class TarantulaMain {
	 
	    public static void main(String[] args) throws ClassNotFoundException {
	    	
	        // create the Matrix Reader to get Test -- Stmt information
	        File f = new File(args[0]/*"/homes/iws/kevinb22/Downloads/triangle-mvn-compact-cov-matrix.json"*/);
	        covMatrixReader reader = new covMatrixReader(f);
	        Long testCountLong = reader.getTestCount();
	        String testCountString = testCountLong.toString();
	        int testCountInt = Integer.parseInt(testCountString);
	        
	        // create Runner class to get the failing cases from JUnit tests
	        Class testClass = Class.forName(args[1]/*"TarantulaCalculator.TriangleTest"*/);
	        Runner r = new Runner(testClass);
	        r.determineFailCases();
	        ArrayList<Integer> fails = r.getFailCases();
	     
	        // set coverage matrix -- [test] [stmt]
	        boolean[][] M = reader.getM();
	        TarantulaSuspiciousnessCalculation calc = new TarantulaSuspiciousnessCalculation(M);
	         
	        // set coverable statements -- [stmt]
	        boolean[] C = reader.getC();
	        calc.setC(C);
	         
	        // set failing test cases -- [test]
	        boolean[] F =new boolean[testCountInt];
	        Arrays.fill(F, false);
	        for(Integer i : fails) {
	            F[i - 1] = true;
	        }
	        calc.setF(F);
	         
	        // set live test cases -- [test]
	        boolean[] L = new boolean[testCountInt];
	        Arrays.fill(L, true);
	        calc.setL(L);
	         
	        calc.compute();
	         
	        System.out.println("For program: " + reader.getFullName());
	        displayConf(calc.getConfidence(), reader.getFirstLine());
	        System.out.println("------------------------------------------------------------------");
	        displaySusp(calc.getSuspiciousness(), reader.getFirstLine());
	    }
	     
	    public static void displayConf(double[] a, Long firstLine){
	        System.out.println("Confidence Array");
	        for(int i = 0; i < a.length; i++) {
	            System.out.println("line " + (i+firstLine) + ": " + a[i]);
	        }
	    }
	     
	    public static void displaySusp(double[] a, Long firstLine){
	        System.out.println("Suspicion Array");
	        for(int i = 0; i < a.length; i++) {
	            System.out.println("line " + (i+firstLine) + ": " + a[i]);
	        }
	    }

}
+766 −0

File added.

Preview size limit exceeded, changes collapsed.

+111 −0

File added.

Preview size limit exceeded, changes collapsed.