Commit 0cce023e authored by Kevin Bi's avatar Kevin Bi
Browse files

"Added class documentation to the tarantula files, changed name of...

"Added class documentation to the tarantula files, changed name of covMatrixReader to CovMatrixReader, updated tarantula README.md to reflect these changes"
parent 4dca8cae
Loading
Loading
Loading
Loading
+21 −24
Original line number Diff line number Diff line
@@ -10,25 +10,23 @@ import org.json.simple.parser.ParseException;
import org.json.simple.parser.JSONParser;

/**
 * This class takes the required information from the compact json file produced by tacoco
 * retrieves program name, first line, test count, coverable lines, and coverage matrix.
 * This class takes reads a compact json file produced by tacoco and
 * retrieves the program name, first line, test count, coverable lines, and coverage matrix.
 * Note that this class can only work with the compact json file produced by tacoco.
 * The matrixes M and C correspond to the values needed in TarantulaSuspiciousnessCalculation.
 * The matrixes M and C correspond to the fields of the same name in TarantulaSuspiciousnessCalculation.
 **/

public class covMatrixReader {
    private File jsonFile;
    private boolean[][] M;
    private boolean[] C;
    private JSONArray sources;
    private Long testCount;
    private Long firstLine;
    private String fullName;
     
     
    public covMatrixReader(){}
     
    public covMatrixReader(File f){
public class CovMatrixReader {
    private File jsonFile;	// Json file to be read from
    private boolean[][] M;	// [test][stmt] matrix for each test and the lines it covers 
    private boolean[] C;	// [stmt] matrix of coverable lines from json file
    private JSONArray sources;	// key in the json file
    private Long testCount;	// number of tests, as stated by the json file
    private Long firstLine;	// first line of the program, as stated by the json file
    private String fullName;	// name of the program, as stated by the json file
    
    /** Initializes a covMatrixReader to read File f **/
    public CovMatrixReader(File f){
        // create a new JSON parser
        JSONParser parser = new JSONParser();
         
@@ -75,11 +73,10 @@ public class covMatrixReader {
        } catch (ParseException e) {
            e.printStackTrace();
        }
 
    }
     
    /** Return a double boolean array where the first dimension is indexed by test number
     * and the second dimension is indexed by line number**/
    and the second dimension is indexed by line number**/
    public boolean[][] getM(){
        return M;
    }
+49 −67
Original line number Diff line number Diff line
@@ -5,7 +5,9 @@ import java.io.File;
import java.util.ArrayList;

/**
 * This program outputs the suspiciousness of each line in a program
 * This class outputs the suspiciousness and confidence of suspiciousness per line of a program. It requires two arguments
 * (1) the file path to a .json coverage matrix (produced by tacoco)
 * (2) the name of the JUnit test class
 */

public class Main {
@@ -14,7 +16,7 @@ import java.util.ArrayList;
	    	
	// create the Matrix Reader to get Test -- Stmt information
	File f = new File(args[0]); // example: "/home/Downloads/triangle-mvn-compact-cov-matrix.json"
	        covMatrixReader reader = new covMatrixReader(f);
	CovMatrixReader reader = new CovMatrixReader(f);
	        
	// The test count is a Long in the Json file, must parse it to an Integer
	Long testCountLong = reader.getTestCount();
@@ -57,28 +59,8 @@ import java.util.ArrayList;
	display(calc.getConfidence(), calc.getSuspiciousness(), reader.getFirstLine());
    }

	    
	// displays the confidence per line of the program starting from the
	// first line of the program identified by tacoco
	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]);
	      }
	   }
	    
	// displays the suspicion per line of the program starting from the
	// first line of the program identified by tacoco
	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]);
	      }
	   }

	
	// displays the suspicion and confidence per line of the program starting from the
	// first line of the program identified by tacoco
    /** Displays the suspicion and confidence per line of the program starting from the
	first line of the program identified by tacoco **/
    public static void display(double[] c, double[] s, Long firstLine){
	for(int i = 0; i < s.length; i++) {
	    System.out.printf("line " + (i+firstLine) + ": suspiciousness: %f, confidence: %f\n", s[i], c[i] );
+2 −2
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ Runner
This program stores the results from a junit tests and holds an array of the test case numbers that fail. All
test headers should be as follows test1, test2, test3 ect. Otherwise the Runner will not work properly.

covMatrixReader
CovMatrixReader
---------------
This program reads the json file produces by tacoco and parses the information into the boolean arrays needed by 
TarantulaSuspiciousnessCalculation. The covMatrixReader is used only to parse information from the compact version of the json
@@ -34,4 +34,4 @@ TarantulaMain
--------------
The main for the project. Requires two command line arguments
	-(1) absolute path to json file - This should be in the tacoco dir after running the scripts in fl-scripts
	-(2) the name of the test program - ex: TestSuite, if the class is in a package include the packace in the name ex: Triangle.TestSuite
	-(2) the name of the test program - TestSuite (the class is in a package include the packace in the name ex: Triangle.TestSuite)
+8 −10
Original line number Diff line number Diff line
package tarantula;

import java.util.ArrayList;
import java.util.List;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

/**
 * This class stores all the failed tests from a Test class
 * This class stores all the failed tests from a JUnit Test class.
 * It requires the the name of the JUnit test class as a parameter for the constructor.
 */

public class Runner {
@@ -17,8 +17,6 @@ public class Runner {
    /** Holds the results from the test program**/
    Result result;
     
    public Runner(){}
     
    @SuppressWarnings("rawtypes")
    /**Initialize a Runner object**/
    public Runner(Class testClass){
@@ -27,7 +25,7 @@ public class Runner {
    }
    
    /** 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 
     * pre: all the test headers must in the format test# (ex: test1, test 10) 
     * post: adds the test header integer segment to the failCases **/
    public void determineFailCases(){
        for (Failure failure : result.getFailures()) {
@@ -38,7 +36,7 @@ public class Runner {
        }
    }   
     
    /**Return the list of the fail cases**/
    /** Return the list containing the fail case indexes**/
    public ArrayList<Integer> getFailCases(){
        return failCases;
    }