jose / smell-free-tests-evosuite

GNU Lesser General Public License v3.0
0 stars 1 forks source link

Método para analisar goals #6

Open fc51111 opened 2 years ago

fc51111 commented 2 years ago

O método que estou a usar para controlar os goals que estão a ser adicionados. Não é muito refinado e dá alguns falsos positivos, mas faz o que tem de fazer. Talvez tente melhorar isto no futuro.

    @Override
    public void addCoveredGoal(TestFitnessFunction goal) {

        int size = this.coveredGoalsClassName.size();
        boolean repeated = false;

        if(goal instanceof LineCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("LineCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(String.valueOf(((LineCoverageTestFitness) goal).getLine()))){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("LineCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(String.valueOf(((LineCoverageTestFitness) goal).getLine()));
        }

        if(goal instanceof BranchCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("BranchCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((BranchCoverageTestFitness) goal).getBranchGoal().toString())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("BranchCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((BranchCoverageTestFitness) goal).getBranchGoal().toString());
        }

        if(goal instanceof ExceptionCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("ExceptionCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((ExceptionCoverageTestFitness) goal).getExceptionClass().toString())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("ExceptionCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((ExceptionCoverageTestFitness) goal).getExceptionClass().toString());
        }

        if(goal instanceof WeakMutationTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("WeakMutationTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((WeakMutationTestFitness) goal).getMutation().toString())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("WeakMutationTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((WeakMutationTestFitness) goal).getMutation().toString());
        }

        if(goal instanceof OutputCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("OutputCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((OutputCoverageTestFitness) goal).getValueDescriptor())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("OutputCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((OutputCoverageTestFitness) goal).getValueDescriptor());
        }

        if(goal instanceof MethodCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("MethodCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((MethodCoverageTestFitness) goal).getMethod())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("MethodCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((MethodCoverageTestFitness) goal).getMethod());
        }

        if(goal instanceof MethodNoExceptionCoverageTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("MethodNoExceptionCoverageTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((MethodNoExceptionCoverageTestFitness) goal).getMethod())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("MethodNoExceptionCoverageTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((MethodNoExceptionCoverageTestFitness) goal).getMethod());
        }

        if(goal instanceof CBranchTestFitness){
            if(!this.coveredGoals.contains(goal)){
                for(int i = 0; i < size; i++){
                    if(this.coveredGoalsType.get(i).equals("CBranchTestFitness")){
                        if(this.coveredGoalsClassName.get(i).equals(goal.getTargetClass()) && this.coveredGoalsMethodName.get(i).equals(goal.getTargetMethod())
                                && this.coveredGoalsContentName.get(i).equals(((CBranchTestFitness) goal).getBranchGoal().toString())){
                            //LoggingUtils.getEvoLogger().info(goal.toString());
                            repeated = true;
                        }
                    }
                }
            } else {
                //LoggingUtils.getEvoLogger().info(goal.toString());
                repeated = true;
            }
            this.coveredGoalsType.add("CBranchTestFitness");
            this.coveredGoalsClassName.add(goal.getTargetClass());
            this.coveredGoalsMethodName.add(goal.getTargetMethod());
            this.coveredGoalsContentName.add(((CBranchTestFitness) goal).getBranchGoal().toString());
        }

        int originalSize = this.coveredGoals.size();

        coveredGoals.add(goal);

        if(repeated && originalSize != this.coveredGoals.size()){
            LoggingUtils.getEvoLogger().info("We Have A Repeated Goal:" + goal.toString());
        }

        // TODO: somehow adds the same goal more than once (fitnessfunction.equals()?)
    }